Skip to content

Commit

Permalink
Remove support for prefix matching in queues assigned to a worker
Browse files Browse the repository at this point in the history
This would generate queries like
```
  WHERE `solid_queue_ready_executions.queue_name` LIKE 'prefix%'
```
that aren't performant enough due to the sorting by priority, so we've
decided not to support these for now.

Thanks to @djmb for the assistance with this.
  • Loading branch information
rosa committed Nov 20, 2023
1 parent 1a5074a commit cd72097
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
10 changes: 1 addition & 9 deletions lib/solid_queue/queue_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(queue_list, relation)
def scoped_relation
if all? then relation.all
else
by_exact_names.or(by_prefixes)
by_exact_names
end
end

Expand All @@ -25,16 +25,8 @@ def by_exact_names
exact_names.any? ? relation.where(queue_name: exact_names) : relation.none
end

def by_prefixes
prefixes.any? ? relation.where(([ "queue_name LIKE ?" ] * prefixes.count).join(" OR "), *prefixes) : relation.none
end

def exact_names
@exact_names ||= raw_queues.select { |queue| !queue.include?("*") }
end

def prefixes
@prefixes ||= raw_queues.select { |queue| queue.ends_with?("*") }.map { |queue| queue.tr("*", "%") }
end
end
end
14 changes: 2 additions & 12 deletions test/models/solid_queue/ready_execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,11 @@ class SolidQueue::ReadyExecutionTest < ActiveSupport::TestCase
end
end

test "claim jobs using queue prefixes" do
AddToBufferJob.perform_later("hey")

assert_claimed_jobs(1) do
SolidQueue::ReadyExecution.claim("backgr*", SolidQueue::Job.count + 1, 42)
end

assert @jobs.none?(&:claimed?)
end

test "claim jobs using both exact names and prefixes" do
test "claim jobs using both exact names and a wildcard" do
AddToBufferJob.perform_later("hey")

assert_claimed_jobs(6) do
SolidQueue::ReadyExecution.claim(%w[ backe* background ], SolidQueue::Job.count + 1, 42)
SolidQueue::ReadyExecution.claim(%w[ * background ], SolidQueue::Job.count + 1, 42)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/unit/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class WorkerTest < ActiveSupport::TestCase
@worker.start(mode: :async)
sleep 0.5

assert_match /SELECT .* FROM .solid_queue_ready_executions. WHERE \(.solid_queue_ready_executions...queue_name./, log.string
assert_match /SELECT .* FROM .solid_queue_ready_executions. WHERE .solid_queue_ready_executions...queue_name./, log.string
ensure
ActiveRecord::Base.logger = old_logger
SolidQueue.silence_polling = old_silence_polling
Expand All @@ -75,7 +75,7 @@ class WorkerTest < ActiveSupport::TestCase
@worker.start(mode: :async)
sleep 0.5

assert_no_match /SELECT .* FROM .solid_queue_ready_executions. WHERE \(.solid_queue_ready_executions...queue_name./, log.string
assert_no_match /SELECT .* FROM .solid_queue_ready_executions. WHERE .solid_queue_ready_executions...queue_name./, log.string
ensure
ActiveRecord::Base.logger = old_logger
SolidQueue.silence_polling = old_silence_polling
Expand Down

0 comments on commit cd72097

Please sign in to comment.