Skip to content

Commit ec42a7e

Browse files
rosaclaude
andcommitted
Select each queue once when several entries in the list match it
A worker listing queue_* and queue_b*, or queue_b* and queue_b1, polled queue_b1 twice on every pass and counted its jobs twice. Prefix matches were never removed from the remaining names, because `queues -= matches` only reassigned the block's local variable, and a queue matched both by name and by a prefix came back from both lookups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3b0506d commit ec42a7e

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎app/models/solid_queue/queue_selector.rb‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def queue_names
3434
def eligible_queues
3535
if include_all_queues? then all_queues
3636
else
37-
in_raw_order(exact_names + prefixed_names)
37+
in_raw_order(exact_names | prefixed_names)
3838
end
3939
end
4040

@@ -89,9 +89,7 @@ def delete_in_order(raw_queue, queues)
8989
queues.delete(raw_queue)
9090
elsif prefixed_name?(raw_queue)
9191
prefix = raw_queue.tr("*", "")
92-
queues.select { |queue| queue.start_with?(prefix) }.tap do |matches|
93-
queues -= matches
94-
end
92+
queues.extract! { |queue| queue.start_with?(prefix) }
9593
end
9694
end
9795
end

‎test/models/solid_queue/ready_execution_test.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ class SolidQueue::ReadyExecutionTest < ActiveSupport::TestCase
196196
claimed_jobs.map(&:queue_name)
197197
end
198198

199+
test "queues matched by more than one entry in the list are selected once" do
200+
AddToBufferJob.set(queue: "queue_b1").perform_later(1)
201+
202+
assert_equal 1, SolidQueue::ReadyExecution.aggregated_count_across(%w[ queue_* queue_b* ])
203+
assert_equal 1, SolidQueue::ReadyExecution.aggregated_count_across(%w[ queue_b* queue_b1 ])
204+
end
205+
199206
test "distinct_values_of returns all distinct queue names" do
200207
AddToBufferJob.perform_later("hey") # goes to background queue
201208

0 commit comments

Comments
 (0)