From e4e3aacb7161a8e53c4088a8df722eca9dae9dfb Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Wed, 15 May 2024 14:21:51 +0200 Subject: [PATCH] ensure retry jobs abandoned after an hour --- app/jobs/retry_mqtt_message_job.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/jobs/retry_mqtt_message_job.rb b/app/jobs/retry_mqtt_message_job.rb index 1d1f507e..e359d6a7 100644 --- a/app/jobs/retry_mqtt_message_job.rb +++ b/app/jobs/retry_mqtt_message_job.rb @@ -1,21 +1,22 @@ class RetryMQTTMessageJob < ApplicationJob class RetryMessageHandlerError < RuntimeError end + queue_as :mqtt_retry - retry_on RetryMessageHandlerError, attempts: 75, wait: ->(count) { + retry_on(RetryMessageHandlerError, attempts: 75, wait: ->(count) { case count when 0..12 5.seconds when 12..20 # Every 30 seconds for the first 5 minutes 30.seconds - when 20..75 # Then every minute for an hour + else # Then every minute for an hour 1.minute - else - :polynomially_longer end - } + }) do |_job, _exeception| + # No-op, this block ensures the exception isn't reraised and retried by Sidekiq + end def perform(topic, message) result = MqttMessagesHandler.handle_topic(topic, message, false)