Skip to content

Commit

Permalink
Allow * to appear anywhere in queue list.
Browse files Browse the repository at this point in the history
  • Loading branch information
tapajos authored and defunkt committed Oct 21, 2011
1 parent 635b50c commit 7bc421a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/resque/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7bc421a

Please sign in to comment.