Skip to content

Commit 50519db

Browse files
committed
MultiQueue#pop returns the Queue object as well
1 parent fbc7838 commit 50519db

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/resque/multi_queue.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(queues, redis)
2525
end
2626

2727
# Pop an item off one of the queues. This method will block until an item
28-
# is available.
28+
# is available. This method returns a tuple of the queue object and job.
2929
#
3030
# Pass +true+ for a non-blocking pop. If nothing is read on a non-blocking
3131
# pop, a ThreadError is raised.
@@ -36,7 +36,7 @@ def pop(non_block = false)
3636

3737
@queues.values.each do |queue|
3838
begin
39-
return queue.pop(true)
39+
return [queue, queue.pop(true)]
4040
rescue ThreadError
4141
end
4242
end
@@ -48,7 +48,8 @@ def pop(non_block = false)
4848
synchronize do
4949
value = @redis.blpop(*(queue_names + [1])) until value
5050
queue_name, payload = value
51-
@queues[queue_name].decode(payload)
51+
queue = @queues[queue_name]
52+
[queue, queue.decode(payload)]
5253
end
5354
end
5455
end

test/multi_queue_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
job = { 'class' => 'GoodJob', 'args' => [35, 'tar'] }
1818
bar << job
19-
assert_equal job, t.join.value
19+
20+
assert_equal [bar, job], t.join.value
2021
end
2122

2223
it "nonblocking pop works" do
@@ -26,7 +27,8 @@
2627

2728
job = { 'class' => 'GoodJob', 'args' => [35, 'tar'] }
2829
bar << job
29-
assert_equal job, queue.pop(true)
30+
31+
assert_equal [bar, job], queue.pop(true)
3032
end
3133

3234
it "blocks forever on pop" do

0 commit comments

Comments
 (0)