canvas-jobs 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32d69dcda463a3ce29b8ff9284868b46c824e3f2
4
- data.tar.gz: 9f06f47a35aa855dbc84f5378ba0bb55f0d3a8e4
3
+ metadata.gz: 06b0d47df9e4e61f3ecb4036f429c02acc0d6cd0
4
+ data.tar.gz: 81246d65f48fbeac3bd230f0917cf02d0ca702b4
5
5
  SHA512:
6
- metadata.gz: c85759b2243f6c81285841c6fdf0fe1bddea1fb7ef11d0c33a71870726961ab5a151adb7c807604801d8bc6dc15f209c83248c34522df41f05c6121b35e787a1
7
- data.tar.gz: e96532599f39295f4acb34536c506c91770a681597ad3e37a145fd0bed91d14b20fb6e4835c54c40908a425badd069df430ecf9f498c481ae1dbdfa0747bda4b
6
+ metadata.gz: 995da9b8ba15ab581a67f26b25931ed1faeda4f6a839aaa07a010ab6e7fddd07a1c6fc0f920d39899d3c70990a7208c17e7fb05fdcada38389aa814086d024e1
7
+ data.tar.gz: 2f809d07cbaf801726610fdb2712807fc8eb762966ec1de580354005ab46d26a0f721821ff25aa6f866bb95fb126be296849b0f856984c2c2b062ecea94ee4c0
data/bin/canvas_job ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('config/environment')
4
+ Delayed::Pool.new.run()
@@ -190,7 +190,7 @@ module Delayed
190
190
  jobs = jobs.sort_by { rand }
191
191
  end
192
192
  job = jobs.detect do |job|
193
- job.lock_exclusively!(worker_name)
193
+ job.send(:lock_exclusively!, worker_name)
194
194
  end
195
195
  return job if job
196
196
  end
@@ -259,7 +259,16 @@ module Delayed
259
259
  def mark_as_locked!(time, worker)
260
260
  self.locked_at = time
261
261
  self.locked_by = worker
262
+ # We cheated ActiveRecord::Dirty with the update_all calls above, so
263
+ # we'll fix things up here.
264
+ if respond_to?(:changes_applied)
265
+ changes_applied
266
+ else
267
+ changed_attributes['locked_at'] = time
268
+ changed_attributes['locked_by'] = worker
269
+ end
262
270
  end
271
+ protected :lock_exclusively!, :mark_as_locked!
263
272
 
264
273
  def create_and_lock!(worker)
265
274
  raise "job already exists" unless new_record?
@@ -140,7 +140,7 @@ local find_available = function(queue, limit, offset, min_priority, max_priority
140
140
  end
141
141
 
142
142
  if not max_priority or max_priority == '' then
143
- max_priority = "+inf"
143
+ max_priority = "(" .. Keys.waiting_strand_job_priority()
144
144
  else
145
145
  max_priority = "(" .. (max_priority + 1)
146
146
  end
@@ -87,31 +87,16 @@ class Job
87
87
  raise("Delayed::MAX_PRIORITY must be less than #{WAITING_STRAND_JOB_PRIORITY}")
88
88
  end
89
89
 
90
- COLUMNS = [
91
- :id,
92
- :priority,
93
- :attempts,
94
- :handler,
95
- :last_error,
96
- :queue,
97
- :run_at,
98
- :locked_at,
99
- :failed_at,
100
- :locked_by,
101
- :created_at,
102
- :updated_at,
103
- :tag,
104
- :max_attempts,
105
- :strand,
106
- :source,
107
- ]
90
+ COLUMNS = []
108
91
 
109
92
  # We store time attributes in redis as floats so we don't have to do
110
93
  # timestamp parsing in lua.
111
- TIMESTAMP_COLUMNS = Set.new([:run_at, :locked_at, :failed_at, :created_at, :updated_at])
112
- INTEGER_COLUMNS = Set.new([:priority, :attempts, :max_attempts])
94
+ TIMESTAMP_COLUMNS = []
95
+ INTEGER_COLUMNS = []
113
96
 
114
97
  def self.column(name, type)
98
+ COLUMNS << name
99
+
115
100
  if type == :timestamp
116
101
  TIMESTAMP_COLUMNS << name
117
102
  elsif type == :integer
@@ -129,9 +114,22 @@ class Job
129
114
  EOS
130
115
  end
131
116
 
132
- COLUMNS.each do |c|
133
- self.column(c, nil)
134
- end
117
+ column(:id, :string)
118
+ column(:priority, :integer)
119
+ column(:attempts, :integer)
120
+ column(:handler, :string)
121
+ column(:last_error, :string)
122
+ column(:queue, :string)
123
+ column(:run_at, :timestamp)
124
+ column(:locked_at, :timestamp)
125
+ column(:failed_at, :timestamp)
126
+ column(:locked_by, :string)
127
+ column(:created_at, :timestamp)
128
+ column(:updated_at, :timestamp)
129
+ column(:tag, :string)
130
+ column(:max_attempts, :integer)
131
+ column(:strand, :string)
132
+ column(:source, :string)
135
133
 
136
134
  def initialize(attrs = {})
137
135
  attrs.each { |k, v| self.send("#{k}=", v) }
@@ -259,7 +257,7 @@ class Job
259
257
  when 'current'
260
258
  query ||= Delayed::Settings.queue
261
259
  check_queue(query)
262
- self.find(functions.find_available(query, limit, offset, nil, nil, db_time_now))
260
+ self.find(functions.find_available(query, limit, offset, 0, "+inf", db_time_now))
263
261
  when 'future'
264
262
  query ||= Delayed::Settings.queue
265
263
  check_queue(query)
@@ -309,6 +307,7 @@ class Job
309
307
  # TODO: mark the job as failed one attempt
310
308
  job.unlock! if job.locked_by == worker_name
311
309
  end
310
+ nil
312
311
  end
313
312
 
314
313
  # returns a list of hashes { :tag => tag_name, :count => current_count }
@@ -1,7 +1,7 @@
1
1
  module Delayed
2
2
  class PerformableMethod < Struct.new(:object, :method, :args)
3
3
  def initialize(object, method, args = [])
4
- raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method)
4
+ raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method, true)
5
5
 
6
6
  self.object = object
7
7
  self.args = args
data/lib/delayed/pool.rb CHANGED
@@ -215,10 +215,16 @@ class Pool
215
215
 
216
216
  def tail_rails_log
217
217
  return if !@options[:tail_logs]
218
- return if !Rails.logger.respond_to?(:log_path)
218
+ if Rails.logger.respond_to?(:log_path)
219
+ log_path = Rails.logger.log_path
220
+ elsif Rails.logger.instance_variable_get('@logdev').try(:instance_variable_get, '@dev').try(:path)
221
+ log_path = Rails.logger.instance_variable_get('@logdev').instance_variable_get('@dev').path
222
+ else
223
+ return
224
+ end
219
225
  Rails.logger.auto_flushing = true if Rails.logger.respond_to?(:auto_flushing=)
220
226
  Thread.new do
221
- f = File.open(Rails.logger.log_path, 'r')
227
+ f = File.open(log_path, 'r')
222
228
  f.seek(0, IO::SEEK_END)
223
229
  loop do
224
230
  content = f.read
@@ -1,3 +1,3 @@
1
1
  module Delayed
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
@@ -82,7 +82,7 @@ class Worker
82
82
  say "Stopping worker", :info
83
83
  rescue => e
84
84
  Rails.logger.fatal("Child process died: #{e.inspect}") rescue nil
85
- self.class.Lifecycle.run_callbacks(:exceptional_exit, self, e) { }
85
+ self.class.lifecycle.run_callbacks(:exceptional_exit, self, e) { }
86
86
  ensure
87
87
  Delayed::Job.clear_locks!(name)
88
88
  end
@@ -32,12 +32,12 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
32
32
 
33
33
  it "should not allow a second worker to get exclusive access if already successfully processed by worker1" do
34
34
  @job.destroy
35
- @job_copy_for_worker_2.lock_exclusively!('worker2').should == false
35
+ @job_copy_for_worker_2.send(:lock_exclusively!, 'worker2').should == false
36
36
  end
37
37
 
38
38
  it "should not allow a second worker to get exclusive access if failed to be processed by worker1 and run_at time is now in future (due to backing off behaviour)" do
39
39
  @job.update_attributes(:attempts => 1, :run_at => 1.day.from_now)
40
- @job_copy_for_worker_2.lock_exclusively!('worker2').should == false
40
+ @job_copy_for_worker_2.send(:lock_exclusively!, 'worker2').should == false
41
41
  end
42
42
 
43
43
  it "should select the next job at random if enabled" do
@@ -57,4 +57,14 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
57
57
  end
58
58
  end
59
59
  end
60
+
61
+ it "should unlock a successfully locked job and persist the job's unlocked state" do
62
+ job = Delayed::Job.create :payload_object => SimpleJob.new
63
+ job.send(:lock_exclusively!, 'worker1').should == true
64
+ job.unlock
65
+ job.save!
66
+ job.reload
67
+ job.locked_by.should == nil
68
+ job.locked_at.should == nil
69
+ end
60
70
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.4)
4
+ canvas-jobs (0.9.5)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.4)
4
+ canvas-jobs (0.9.5)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.4)
4
+ canvas-jobs (0.9.5)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- canvas-jobs (0.9.4)
4
+ canvas-jobs (0.9.5)
5
5
  after_transaction_commit (= 1.0.1)
6
6
  rails (>= 3.2)
7
7
  redis (> 3.0)
@@ -270,6 +270,14 @@ shared_examples_for 'a backend' do
270
270
  Delayed::Job.get_and_lock_next_available('w3').should == nil
271
271
  end
272
272
 
273
+ it "should not find next jobs when given no priority" do
274
+ jobs = [create_job(:strand => 'strand1'), create_job(:strand => 'strand1')]
275
+ first = Delayed::Job.get_and_lock_next_available('w1', Delayed::Settings.queue, nil, nil)
276
+ second = Delayed::Job.get_and_lock_next_available('w2', Delayed::Settings.queue, nil, nil)
277
+ expect(first).to eq jobs.first
278
+ expect(second).to eq nil
279
+ end
280
+
273
281
  context 'singleton' do
274
282
  it "should create if there's no jobs on the strand" do
275
283
  @job = create_job(:singleton => 'myjobs')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-22 00:00:00.000000000 Z
12
+ date: 2014-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: after_transaction_commit
@@ -210,10 +210,12 @@ dependencies:
210
210
  description:
211
211
  email:
212
212
  - brianp@instructure.com
213
- executables: []
213
+ executables:
214
+ - canvas_job
214
215
  extensions: []
215
216
  extra_rdoc_files: []
216
217
  files:
218
+ - bin/canvas_job
217
219
  - db/migrate/20101216224513_create_delayed_jobs.rb
218
220
  - db/migrate/20110208031356_add_delayed_jobs_tag.rb
219
221
  - db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb
@@ -298,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
300
  version: '0'
299
301
  requirements: []
300
302
  rubyforge_project:
301
- rubygems_version: 2.4.1
303
+ rubygems_version: 2.4.2
302
304
  signing_key:
303
305
  specification_version: 4
304
306
  summary: Instructure-maintained fork of delayed_job
@@ -323,4 +325,3 @@ test_files:
323
325
  - spec/shared/worker.rb
324
326
  - spec/shared_jobs_specs.rb
325
327
  - spec/spec_helper.rb
326
- has_rdoc: