Skip to content

Commit

Permalink
ensure retry jobs abandoned after an hour
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed May 15, 2024
1 parent 4e9775e commit e4e3aac
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/jobs/retry_mqtt_message_job.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit e4e3aac

Please sign in to comment.