Skip to content

Commit 8bbc757

Browse files
committed
Don't override ActiveRecord::QueryMethods#lock but create a different method
Depending on the load order, it might end up skipping the override and using the original one, leading to slow queries using SELECT ... FOR UPDATE.
1 parent dd61760 commit 8bbc757

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

app/models/solid_queue/blocked_execution.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def release_many(concurrency_keys)
2424

2525
def release_one(concurrency_key)
2626
transaction do
27-
ordered.where(concurrency_key: concurrency_key).limit(1).lock.each(&:release)
27+
ordered.where(concurrency_key: concurrency_key).limit(1).non_blocking_lock.each(&:release)
2828
end
2929
end
3030

app/models/solid_queue/process/prunable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module SolidQueue::Process::Prunable
99

1010
class_methods do
1111
def prune
12-
prunable.lock.find_in_batches(batch_size: 50) do |batch|
12+
prunable.non_blocking_lock.find_in_batches(batch_size: 50) do |batch|
1313
batch.each do |process|
1414
SolidQueue.logger.info("[SolidQueue] Pruning dead process #{process.id} - #{process.metadata}")
1515
process.deregister

app/models/solid_queue/ready_execution.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def select_and_lock(queue_relation, process_id, limit)
2626
end
2727

2828
def select_candidates(queue_relation, limit)
29-
queue_relation.ordered.limit(limit).lock.pluck(:job_id)
29+
queue_relation.ordered.limit(limit).non_blocking_lock.pluck(:job_id)
3030
end
3131

3232
def lock_candidates(job_ids, process_id)

app/models/solid_queue/record.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class Record < ActiveRecord::Base
66

77
connects_to **SolidQueue.connects_to if SolidQueue.connects_to
88

9-
def self.lock(...)
9+
def self.non_blocking_lock
1010
if SolidQueue.use_skip_locked
11-
super(Arel.sql("FOR UPDATE SKIP LOCKED"))
11+
lock(Arel.sql("FOR UPDATE SKIP LOCKED"))
1212
else
13-
super
13+
lock
1414
end
1515
end
1616
end

app/models/solid_queue/scheduled_execution.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ScheduledExecution < Execution
1111
class << self
1212
def dispatch_next_batch(batch_size)
1313
transaction do
14-
job_ids = next_batch(batch_size).lock.pluck(:job_id)
14+
job_ids = next_batch(batch_size).non_blocking_lock.pluck(:job_id)
1515
if job_ids.empty? then []
1616
else
1717
dispatch_batch(job_ids)

0 commit comments

Comments
 (0)