Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the order in which queues/patterns are defined #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/resque/plugins/dynamic_queues/queues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def queues_with_dynamic

return queues_without_dynamic if queue_names.grep(/(^!)|(^@)|(\*)/).size == 0

real_queues = Resque.queues
real_queues = Resque.queues.sort
matched_queues = []

while q = queue_names.shift
Expand Down Expand Up @@ -54,7 +54,7 @@ def queues_with_dynamic
end
end

return matched_queues.uniq.sort
return matched_queues.uniq
end


Expand Down
17 changes: 14 additions & 3 deletions spec/queues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,25 @@
worker.queues.should == ["foo"]
end

it "respects the order in which queue patterns are defined" do
worker = Resque::Worker.new("h*", "f*")
worker.queues.should == ["high_x", "high_y", "foo"]

worker = Resque::Worker.new("*", "!f*")
worker.queues.should == ["high_x", "high_y", "superhigh_z"]

worker = Resque::Worker.new("*high*_z", "*", "!f*")
worker.queues.should == ["superhigh_z", "high_x", "high_y"]
end

end

context "redis backed queues" do

it "can dynamically lookup queues" do
Resque.set_dynamic_queue("mykey", ["foo", "bar"])
worker = Resque::Worker.new("@mykey")
worker.queues.should == ["bar", "foo"]
worker.queues.should == ["foo", "bar"]
end

it "can blacklist dynamic queues" do
Expand Down Expand Up @@ -180,7 +191,7 @@
host = `hostname`.chomp
Resque.set_dynamic_queue(host, ["foo", "bar"])
worker = Resque::Worker.new("@")
worker.queues.should == ["bar", "foo"]
worker.queues.should == ["foo", "bar"]
end

it "can use wildcards in dynamic queues" do
Expand All @@ -197,7 +208,7 @@
it "falls back to default queues when missing" do
Resque.set_dynamic_queue("default", ["foo", "bar"])
worker = Resque::Worker.new("@mykey")
worker.queues.should == ["bar", "foo"]
worker.queues.should == ["foo", "bar"]
end

it "falls back to all queues when missing and no default" do
Expand Down