From c8d27b2963af122d6555abdf0742d2d2d6f11ce5 Mon Sep 17 00:00:00 2001 From: Charlie Smurthwaite Date: Wed, 22 Mar 2023 14:02:28 +0000 Subject: [PATCH] Change retry and batching timing calculations (#2371) This patch changes the requeue behaviour to requeue messages that are 30 seconds past their retry time. Batching now includes messages that are any amount past their retry time. This change avoids batching messages before theur graylisting time, but maintains efficient batching. --- app/models/queued_message.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/queued_message.rb b/app/models/queued_message.rb index d34c07e..d0dc276 100644 --- a/app/models/queued_message.rb +++ b/app/models/queued_message.rb @@ -36,10 +36,11 @@ class QueuedMessage < ApplicationRecord after_commit :queue, on: :create scope :unlocked, -> { where(locked_at: nil) } - scope :retriable, -> { where("retry_after IS NULL OR retry_after <= ?", 30.seconds.from_now) } + scope :retriable, -> { where("retry_after IS NULL OR retry_after < ?", Time.now) } + scope :requeueable, -> { where("retry_after IS NULL OR retry_after < ?", 30.seconds.ago) } def retriable? - retry_after.nil? || retry_after <= 30.seconds.from_now + retry_after.nil? || retry_after < Time.now end def queue @@ -117,7 +118,7 @@ class QueuedMessage < ApplicationRecord end def self.requeue_all - unlocked.retriable.each(&:queue) + unlocked.requeueable.each(&:queue) end end