Skip to content

Commit 3425926

Browse files
authored
Merge pull request #2 from jfahrer/master
Return queues in order they were defined/matched
2 parents 8af7bb1 + 87c9e71 commit 3425926

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/resque/plugins/dynamic_queues/queues.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def queues_with_dynamic
2424

2525
return queues_without_dynamic if queue_names.grep(dynamic_pattern).size == 0
2626

27-
real_queues = Resque.queues
27+
real_queues = Resque.queues.sort
2828
matched_queues = []
2929

3030
while q = queue_names.shift
@@ -57,7 +57,7 @@ def queues_with_dynamic
5757
end
5858
end
5959

60-
return matched_queues.uniq.sort
60+
return matched_queues.uniq
6161
end
6262

6363

spec/queues_spec.rb

+14-3
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,25 @@
139139
worker.queues.should == ["foo"]
140140
end
141141

142+
it "respects the order in which queue patterns are defined" do
143+
worker = Resque::Worker.new("h*", "f*")
144+
worker.queues.should == ["high_x", "high_y", "foo"]
145+
146+
worker = Resque::Worker.new("*", "!f*")
147+
worker.queues.should == ["high_x", "high_y", "superhigh_z"]
148+
149+
worker = Resque::Worker.new("*high*_z", "*", "!f*")
150+
worker.queues.should == ["superhigh_z", "high_x", "high_y"]
151+
end
152+
142153
end
143154

144155
context "redis backed queues" do
145156

146157
it "can dynamically lookup queues" do
147158
Resque.set_dynamic_queue("mykey", ["foo", "bar"])
148159
worker = Resque::Worker.new("@mykey")
149-
worker.queues.should == ["bar", "foo"]
160+
worker.queues.should == ["foo", "bar"]
150161
end
151162

152163
it "can blacklist dynamic queues" do
@@ -185,7 +196,7 @@
185196
host = `hostname`.chomp
186197
Resque.set_dynamic_queue(host, ["foo", "bar"])
187198
worker = Resque::Worker.new("@")
188-
worker.queues.should == ["bar", "foo"]
199+
worker.queues.should == ["foo", "bar"]
189200
end
190201

191202
it "can use wildcards in dynamic queues" do
@@ -202,7 +213,7 @@
202213
it "falls back to default queues when missing" do
203214
Resque.set_dynamic_queue("default", ["foo", "bar"])
204215
worker = Resque::Worker.new("@mykey")
205-
worker.queues.should == ["bar", "foo"]
216+
worker.queues.should == ["foo", "bar"]
206217
end
207218

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

0 commit comments

Comments
 (0)