talentbox-delayed_job_sequel 4.0.0.beta1 → 4.0.0.beta1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,16 +37,24 @@ module Delayed
37
37
  filter(:locked_by => worker_name).update(:locked_by => nil, :locked_at => nil)
38
38
  end
39
39
 
40
- # Find a few candidate jobs to run (in case some immediately get locked by others).
41
- def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
42
- set = ready_to_run(worker_name, max_run_time)
40
+ def self.reserve(worker, max_run_time = Worker.max_run_time)
41
+ set = ready_to_run(worker.name, max_run_time)
43
42
  set = set.filter("priority >= ?", Worker.min_priority) if Worker.min_priority
44
43
  set = set.filter("priority <= ?", Worker.max_priority) if Worker.max_priority
45
44
  set = set.filter(:queue => Worker.queues) if Worker.queues.any?
46
45
 
47
- silence_log do
48
- set.by_priority.limit(limit).all
46
+ job = set.by_priority.first
47
+
48
+ now = self.db_time_now
49
+
50
+ return unless job
51
+ model.db.transaction do
52
+ job.lock!
53
+ job.locked_at = now
54
+ job.locked_by = worker.name
55
+ job.save(:raise_on_failure => true)
49
56
  end
57
+ job
50
58
  end
51
59
 
52
60
  # Lock this job for this worker.
@@ -134,7 +142,7 @@ module Delayed
134
142
  end
135
143
  end
136
144
 
137
- # The default behaviour for sequel on #==/#eql? is to check if all
145
+ # The default behaviour for sequel on #==/#eql? is to check if all
138
146
  # values are matching.
139
147
  # This differs from ActiveRecord which checks class and id only.
140
148
  # To pass the specs we're reverting to what AR does here.
data/spec/spec_helper.rb CHANGED
@@ -53,7 +53,7 @@ end
53
53
  require "delayed_job_sequel"
54
54
  require "delayed/backend/shared_spec"
55
55
 
56
- Delayed::Worker.logger = Logger.new("/tmp/dj.log")
56
+ Delayed::Worker.logger = Logger.new(ENV["DEBUG"] ? $stdout : "/tmp/dj.log")
57
57
  DB.logger = Delayed::Worker.logger
58
58
 
59
59
  # Purely useful for test cases...
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: talentbox-delayed_job_sequel
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 4.0.0.beta1
5
+ version: 4.0.0.beta1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jonathan Tron
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  segments:
127
127
  - 0
128
- hash: -1333829786726044659
128
+ hash: 3436972036027455601
129
129
  version: '0'
130
130
  none: false
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement