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.
This commit is contained in:
Charlie Smurthwaite
2023-03-22 14:02:28 +00:00
committed by GitHub
parent c6fb8d223b
commit c8d27b2963
+4 -3
View File
@@ -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