Skip to content

Commit

Permalink
Factor in paused queues when polling for ready jobs to claim
Browse files Browse the repository at this point in the history
  • Loading branch information
rosa committed Oct 25, 2023
1 parent 1253c9d commit fb33ee7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/solid_queue/ready_execution.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module SolidQueue
class ReadyExecution < Execution
scope :ordered, -> { order(priority: :asc) }
scope :not_paused, -> { where.not(queue_name: Pause.all_queue_names) }

before_create :assume_attributes_from_job

Expand All @@ -24,7 +25,7 @@ def queued_as(queues)

private
def query_candidates(queues, limit)
queued_as(queues).ordered.limit(limit).lock("FOR UPDATE SKIP LOCKED").pluck(:job_id)
queued_as(queues).not_paused.ordered.limit(limit).lock("FOR UPDATE SKIP LOCKED").pluck(:job_id)
end

def lock(job_ids)
Expand Down
11 changes: 11 additions & 0 deletions test/models/solid_queue/ready_execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ class SolidQueue::ReadyExecutionTest < ActiveSupport::TestCase
end
end

test "claim jobs using a wildcard and having paused queues" do
other_jobs = SolidQueue::Job.all - @jobs
other_jobs.each(&:prepare_for_execution)

SolidQueue::Queue.find_by_name("fixtures").pause

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

test "claim jobs using queue prefixes" do
assert_claimed_jobs(2) do
SolidQueue::ReadyExecution.claim("fix*", 2)
Expand Down

0 comments on commit fb33ee7

Please sign in to comment.