Skip to content

Commit ffaa819

Browse files
Kelley Reynoldssteveklabnik
authored andcommitted
Add the ability to specify low-priority queues after a splat and preserve order
1 parent 8fdfe5b commit ffaa819

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/resque/worker.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,11 @@ def reserve(interval = 5.0)
223223

224224
# Returns a list of queues to use when searching for a job.
225225
# A splat ("*") means you want every queue (in alpha order) - this
226-
# can be useful for dynamically adding new queues.
226+
# can be useful for dynamically adding new queues. Low priority queues
227+
# can be placed after a splat to ensure execution after all other dynamic
228+
# queues.
227229
def queues
228-
@queues.map {|queue| queue == "*" ? Resque.queues.sort : queue }.flatten.uniq
230+
@queues.map {|queue| queue == "*" ? (Resque.queues - @queues).sort : queue }.flatten.uniq
229231
end
230232

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

test/worker_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ def self.perform
179179
assert_equal 0, Resque.size(:beer)
180180
end
181181

182+
it "preserves order with a wildcard in the middle of a list" do
183+
Resque::Job.create(:critical, GoodJob)
184+
Resque::Job.create(:bulk, GoodJob)
185+
186+
worker = Resque::Worker.new(:beer, "*", :bulk)
187+
188+
assert_equal %w( beer critical jobs bulk ), worker.queues
189+
end
190+
182191
it "processes * queues in alphabetical order" do
183192
Resque::Job.create(:high, GoodJob)
184193
Resque::Job.create(:critical, GoodJob)

0 commit comments

Comments
 (0)