Skip to content

Commit 7bc421a

Browse files
tapajosdefunkt
authored andcommitted
Allow * to appear anywhere in queue list.
Fixes resque#405 Fixes resque#407
1 parent 635b50c commit 7bc421a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/resque/worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def reserve
210210
# A splat ("*") means you want every queue (in alpha order) - this
211211
# can be useful for dynamically adding new queues.
212212
def queues
213-
@queues[0] == "*" ? Resque.queues.sort : @queues
213+
@queues.map {|queue| queue == "*" ? Resque.queues.sort : queue }.flatten.uniq
214214
end
215215

216216
# Not every platform supports fork. Here we do our magic to

test/worker_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,36 @@ def self.exception
115115
assert_equal 0, Resque.size(:blahblah)
116116
end
117117

118+
test "can work with wildcard at the end of the list" do
119+
Resque::Job.create(:high, GoodJob)
120+
Resque::Job.create(:critical, GoodJob)
121+
Resque::Job.create(:blahblah, GoodJob)
122+
Resque::Job.create(:beer, GoodJob)
123+
124+
worker = Resque::Worker.new(:critical, :high, "*")
125+
126+
worker.work(0)
127+
assert_equal 0, Resque.size(:high)
128+
assert_equal 0, Resque.size(:critical)
129+
assert_equal 0, Resque.size(:blahblah)
130+
assert_equal 0, Resque.size(:beer)
131+
end
132+
133+
test "can work with wildcard at the middle of the list" do
134+
Resque::Job.create(:high, GoodJob)
135+
Resque::Job.create(:critical, GoodJob)
136+
Resque::Job.create(:blahblah, GoodJob)
137+
Resque::Job.create(:beer, GoodJob)
138+
139+
worker = Resque::Worker.new(:critical, "*", :high)
140+
141+
worker.work(0)
142+
assert_equal 0, Resque.size(:high)
143+
assert_equal 0, Resque.size(:critical)
144+
assert_equal 0, Resque.size(:blahblah)
145+
assert_equal 0, Resque.size(:beer)
146+
end
147+
118148
test "processes * queues in alphabetical order" do
119149
Resque::Job.create(:high, GoodJob)
120150
Resque::Job.create(:critical, GoodJob)

0 commit comments

Comments
 (0)