Permalink
Browse files

Allow `*` to appear anywhere in queue list.

Fixes #405
Fixes #407
  • Loading branch information...
1 parent 635b50c commit 7bc421a98272e31c6accbd2f8b17af5586b775cb @tapajos tapajos committed with defunkt Sep 28, 2011
Showing with 31 additions and 1 deletion.
  1. +1 −1 lib/resque/worker.rb
  2. +30 −0 test/worker_test.rb
@@ -210,7 +210,7 @@ def reserve
# A splat ("*") means you want every queue (in alpha order) - this
# can be useful for dynamically adding new queues.
def queues
- @queues[0] == "*" ? Resque.queues.sort : @queues
+ @queues.map {|queue| queue == "*" ? Resque.queues.sort : queue }.flatten.uniq
end
# Not every platform supports fork. Here we do our magic to
View
@@ -115,6 +115,36 @@ def self.exception
assert_equal 0, Resque.size(:blahblah)
end
+ test "can work with wildcard at the end of the list" do
+ Resque::Job.create(:high, GoodJob)
+ Resque::Job.create(:critical, GoodJob)
+ Resque::Job.create(:blahblah, GoodJob)
+ Resque::Job.create(:beer, GoodJob)
+
+ worker = Resque::Worker.new(:critical, :high, "*")
+
+ worker.work(0)
+ assert_equal 0, Resque.size(:high)
+ assert_equal 0, Resque.size(:critical)
+ assert_equal 0, Resque.size(:blahblah)
+ assert_equal 0, Resque.size(:beer)
+ end
+
+ test "can work with wildcard at the middle of the list" do
+ Resque::Job.create(:high, GoodJob)
+ Resque::Job.create(:critical, GoodJob)
+ Resque::Job.create(:blahblah, GoodJob)
+ Resque::Job.create(:beer, GoodJob)
+
+ worker = Resque::Worker.new(:critical, "*", :high)
+
+ worker.work(0)
+ assert_equal 0, Resque.size(:high)
+ assert_equal 0, Resque.size(:critical)
+ assert_equal 0, Resque.size(:blahblah)
+ assert_equal 0, Resque.size(:beer)
+ end
+
test "processes * queues in alphabetical order" do
Resque::Job.create(:high, GoodJob)
Resque::Job.create(:critical, GoodJob)

0 comments on commit 7bc421a

Please sign in to comment.