Batch webhook delivery cleanup to prevent DB lock contention (#2555)
Follow-up to #2550 which added a created_at index and increased cleanup frequency. The delete itself was still unbatched and vulnerable whenever a backlog accumulates (first run after deploy, clock skew, etc). Delete in small batches with a pause between each to let other transactions through, following the SolidQueue pattern.
This commit is contained in:
@@ -22,8 +22,8 @@ class Webhook::Delivery < ApplicationRecord
|
||||
|
||||
after_create_commit :deliver_later
|
||||
|
||||
def self.cleanup
|
||||
stale.delete_all
|
||||
def self.cleanup(batch_size: 500, pause: 0.1)
|
||||
sleep pause until stale.limit(batch_size).delete_all.zero?
|
||||
end
|
||||
|
||||
def deliver_later
|
||||
|
||||
Reference in New Issue
Block a user