blaxter-delayed_job 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.1
data/lib/delayed/job.rb CHANGED
@@ -24,7 +24,7 @@ module Delayed
24
24
  cattr_accessor :destroy_successful_jobs
25
25
  self.destroy_successful_jobs = false
26
26
 
27
- NextTaskSQL = '(run_at <= ? AND (locked_at IS NULL OR locked_at < ?)) AND failed_at IS NULL AND finished_at IS NULL'
27
+ NextTaskSQL = '(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR (locked_by = ?)) AND failed_at IS NULL AND finished_at IS NULL'
28
28
  NextTaskOrder = 'priority DESC, run_at ASC'
29
29
 
30
30
  ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/
@@ -75,7 +75,7 @@ module Delayed
75
75
 
76
76
  sql = NextTaskSQL.dup
77
77
  time_now = db_time_now
78
- conditions = [time_now, time_now - max_run_time]
78
+ conditions = [time_now, time_now - max_run_time, worker_name]
79
79
  if options[:min_priority]
80
80
  sql << ' AND (priority >= ?)'
81
81
  conditions << options[:min_priority]
@@ -246,13 +246,7 @@ module Delayed
246
246
  # Simply resume and update the locked_at
247
247
  self.class.update_all(["locked_at = ?", now], ["id = ? and locked_by = ?", id, worker])
248
248
  end
249
- if affected_rows == 1
250
- self.locked_at = now
251
- self.locked_by = worker
252
- return true
253
- else
254
- return false
255
- end
249
+ affected_rows == 1 && reload
256
250
  end
257
251
 
258
252
  # Unlock this job (note: not saved to DB)
@@ -90,11 +90,16 @@ module Delayed
90
90
 
91
91
  # Whether we can or not execute this job
92
92
  def can_execute(job)
93
+ return false if is_already_in_execution(job)
93
94
  object = get_object(job)
94
95
  object && ! is_there_job_in_execution_for(object) &&
95
96
  jobs_in_execution < @max_active_jobs
96
97
  end
97
98
 
99
+ def is_already_in_execution(job)
100
+ !! @jobs.values.detect {|h| h[:job].id == job.id }
101
+ end
102
+
98
103
  def each_job_in_execution
99
104
  @jobs.each_pair do |key, value|
100
105
  yield value[:job], value[:started_at], value[:thread]
data/spec/job_spec.rb CHANGED
@@ -428,10 +428,10 @@ describe Delayed::Job do
428
428
  SimpleJob.runs.should == 1 # runs the one open job
429
429
  end
430
430
 
431
- it "should find only ur own jobs unless they are locked" do
431
+ it "should find our own jobs regardless of locks" do
432
432
  SimpleJob.runs.should == 0
433
433
  Delayed::Job.work_off :worker_name => 'worker1'
434
- SimpleJob.runs.should == 1 # runs open job, no worker1 jobs that were already locked
434
+ SimpleJob.runs.should == 3 # runs open job plus worker1 jobs that were already locked
435
435
  end
436
436
  end
437
437
 
@@ -453,7 +453,9 @@ describe Delayed::Job do
453
453
  it "should ignore locks when finding our own jobs" do
454
454
  SimpleJob.runs.should == 0
455
455
  Delayed::Job.work_off :worker_name => 'worker1'
456
- SimpleJob.runs.should == 2 # runs open job plus worker1 jobs (unless locked)
456
+ SimpleJob.runs.should == 3 # runs open job plus worker1 jobs
457
+ # This is useful in the case of a crash/restart on worker1,
458
+ # but make sure multiple workers on the same host have unique names!
457
459
  end
458
460
 
459
461
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blaxter-delayed_job
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 0
10
- version: 2.1.0
9
+ - 1
10
+ version: 2.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Tobias L\xC3\xBCtke"