Skip to content

Commit 816c6a8

Browse files
committed
Use SKIP LOCKED by default but allow not using it if not supported
This is a setting for now, but will be automatically detected on start later.
1 parent da3a2ca commit 816c6a8

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
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("FOR UPDATE SKIP LOCKED").each(&:release)
27+
ordered.where(concurrency_key: concurrency_key).limit(1).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("FOR UPDATE SKIP LOCKED").find_in_batches(batch_size: 50) do |batch|
12+
prunable.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("FOR UPDATE SKIP LOCKED").pluck(:job_id)
29+
queue_relation.ordered.limit(limit).lock.pluck(:job_id)
3030
end
3131

3232
def lock_candidates(job_ids, process_id)

app/models/solid_queue/record.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ class Record < ActiveRecord::Base
55
self.abstract_class = true
66

77
connects_to **SolidQueue.connects_to if SolidQueue.connects_to
8+
9+
def self.lock(...)
10+
if SolidQueue.use_skip_locked
11+
super(Arel.sql("FOR UPDATE SKIP LOCKED"))
12+
else
13+
super
14+
end
15+
end
816
end
917
end
1018

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("FOR UPDATE SKIP LOCKED").pluck(:job_id)
14+
job_ids = next_batch(batch_size).lock.pluck(:job_id)
1515
if job_ids.empty? then []
1616
else
1717
dispatch_batch(job_ids)

lib/solid_queue.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ module SolidQueue
2626
mattr_accessor :logger, default: ActiveSupport::Logger.new($stdout)
2727
mattr_accessor :app_executor, :on_thread_error, :connects_to
2828

29+
mattr_accessor :use_skip_locked, default: true
30+
2931
mattr_accessor :process_heartbeat_interval, default: 60.seconds
3032
mattr_accessor :process_alive_threshold, default: 5.minutes
3133

0 commit comments

Comments
 (0)