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:
Jeremy Daer
2026-02-16 15:31:10 -08:00
committed by GitHub
parent 0ead67f85b
commit a253c31dee
+2 -2
View File
@@ -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