Class: Resque::MultiQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/resque-priority-jobs/multi_queue.rb

Instance Method Summary collapse

Instance Method Details

#poll_with_priority(timeout) ⇒ Object Also known as: poll

worker polling aliased TODO: Known Performance issue to ensure that same job is not done twice. Can be fixed after redis-2.6 is released



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/resque-priority-jobs/multi_queue.rb', line 5

def poll_with_priority timeout
  normal_queue_names = @queues.map {|queue| queue.redis_name  unless queue.is_a_priority_queue? }
  normal_queue_names.compact!
  priority_queue_names = @queues.map {|queue| queue.redis_name if queue.is_a_priority_queue? }
  priority_queue_names.compact!
  priority_queue_names.each do |queue_name|
    synchronize do
      payload = Resque::JobFetch.fetch_one_job @redis, queue_name
      if payload
        queue = @queue_hash[queue_name]
        return [queue, queue.decode(payload)]
      end
    end
  end
  normal_queue_names = normal_queue_names.size == 0 ? "" : normal_queue_names
  queue_name, payload = @redis.blpop(normal_queue_names, :timeout => timeout)
  return unless payload

  synchronize do
    queue = @queue_hash[queue_name]
    [queue, queue.decode(payload)]
  end
end