Adds mechanism to avoid too many retries

This commit is contained in:
Brusk Awat 2023-04-05 23:52:00 +03:00
parent fd69f23345
commit 2647c47b53
Signed by: broosk1993
GPG Key ID: 5D20F7E02649F74E

View File

@ -4,11 +4,13 @@ module Outboxable
sidekiq_options queue: 'critical' sidekiq_options queue: 'critical'
def perform def perform
Outbox.pending.find_in_batches(batch_size: 100).each do |batch| Outbox.pending.where(last_attempted_at: [..Time.zone.now, nil]).find_in_batches(batch_size: 100).each do |batch|
batch.each do |outbox| batch.each do |outbox|
# This is to prevent a job from being retried too many times. Worst-case scenario is 1 minute delay in jobs.
outbox.update(last_attempted_at: 1.minute.from_now)
Outboxable::Worker.perform_async(outbox.id) Outboxable::Worker.perform_async(outbox.id)
end end
end end
end end
end end
end end