I am migrating a background job processing service made with sidekiq to shoryuken, which is based on Amazon SQS.
With sidekiq you can customize the retries pattern by using sidekiq_retry_in:
class WorkerWithCustomRetry
include Sidekiq::Worker
sidekiq_options :retry => 5
sidekiq_retry_in do |count|
retry_count(count)
end
def self.retry_count(count)
...
end
end
where, in my case, retry_countreturns the delay for the next retry based on external configuration.
With shoryuken retries are yielded to SQS which handle retries automatically as long as the message is not deleted by the consumer application. However with shoryuken you can change the delay by using retry_intervals but documentation only explains how to set fixed values:
class MyWorker
include Shoryuken::Worker
shoryuken_options queue: 'default', retry_intervals: [360, 1200, 3600] # 5.minutes, 20.minutes and 1.hour
end
I need to customize the delay for retries the same way as with sidekiq, using a retry_count method which returns different values depending on external data. Is this possible or does exist a workaround to do that with shoryuken?
Currently Shoryuken only supports fixed values for exponential backoff, but you can submit a PR changing ExponentialBackoffRetry with:
So you will be able to use a proc or fixed values to set
retry_intervals, i.e.:OR you can remove the default
ExponentialBackoffRetryand add yours:But keep in mind that SQS does not officially support exponential backoff, it's something implemented in Shoryuken using the Visibility Timeout, which can extended to a maximum of 12 hours.