Skip to content

Commit

Permalink
switch Worker#reserve to non blocking MultiQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
hone committed Apr 14, 2012
1 parent 50519db commit 6951307
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/resque/worker.rb
Expand Up @@ -193,19 +193,15 @@ def perform(job)
# Attempts to grab a job off one of the provided queues. Returns
# nil if no job can be found.
def reserve
queues.each do |queue|
log! "Checking #{queue}"
if job = Resque.reserve(queue)
log! "Found job on #{queue}"
return job
end
end

multi_queue = MultiQueue.new(
queues.map {|queue| Queue.new(queue, Resque.redis, Resque.coder) },
Resque.redis)

queue, job = multi_queue.pop(true)
log! "Found job on #{queue}"
return Job.new(queue.name, job)
rescue ThreadError
nil
rescue Exception => e
log "Error reserving job: #{e.inspect}"
log e.backtrace.join("\n")
raise e
end

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

0 comments on commit 6951307

Please sign in to comment.