Skip to content

Commit f03ba93

Browse files
committed
reserve returns nil when there is no job
1 parent f2d0a7c commit f03ba93

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/resque/worker.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,18 @@ def reserve(interval = 5.0)
199199
queues.map {|queue| Queue.new(queue, Resque.redis, Resque.coder) },
200200
Resque.redis)
201201

202-
if interval < 1
203-
queue, job = multi_queue.pop(true)
202+
queue, job = if interval < 1
203+
begin
204+
multi_queue.pop(true)
205+
rescue ThreadError
206+
nil
207+
end
204208
else
205209
queue, job = multi_queue.poll(interval.to_i)
206210
end
207211

208212
log! "Found job on #{queue}"
209-
return Job.new(queue.name, job)
210-
rescue ThreadError
211-
nil
213+
Job.new(queue.name, job) if queue && job
212214
end
213215

214216
# Returns a list of queues to use when searching for a job.

test/worker_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ def self.exception
272272
end
273273
end
274274

275+
it "reserve returns nil when there is no job and is polling" do
276+
worker = Resque::Worker.new(:timeout)
277+
278+
assert_equal nil, worker.reserve(1)
279+
end
280+
275281
it "keeps track of how many failures it has seen" do
276282
Resque::Job.create(:jobs, BadJob)
277283
Resque::Job.create(:jobs, BadJob)

0 commit comments

Comments
 (0)