From 2647c47b53596d57629394f5a6d4d85d0622aec9 Mon Sep 17 00:00:00 2001 From: Brusk Awat Date: Wed, 5 Apr 2023 23:52:00 +0300 Subject: [PATCH] Adds mechanism to avoid too many retries --- lib/outboxable/polling_publisher_worker.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/outboxable/polling_publisher_worker.rb b/lib/outboxable/polling_publisher_worker.rb index 22ce75c..3d02383 100644 --- a/lib/outboxable/polling_publisher_worker.rb +++ b/lib/outboxable/polling_publisher_worker.rb @@ -4,11 +4,13 @@ module Outboxable sidekiq_options queue: 'critical' 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| + # 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) end end end end -end \ No newline at end of file +end