Is there a way to get the retry count for the current job? I want to know whether it's retry #1, #2, #3, etc.
Nope. Retry is designed to be orthogonal to the job. You can access it from a custom middleware.
@mperham is there any reason do not give access to the retry_count?
I found a few workarounds (1 and 2) but I don't understand why retry_count is not a part of standard API
I use Sidekiq to deliver web_hooks to clients and if some web_hook fails the delivery should be retried 30 times (for 60 days). But I want to notify a client about the issue starting from 5th attempt (don't bother the client if he has a short downtime) and I would expect something like this:
class WebhookWorker
include Sidekiq::Worker
sidekiq_options queue: :webhook
def perform(*args)
# send webhook
rescue WebHook::Error => ex
ApplicationErrors.notify_client(...) if retry_count > 4
raise ex
end
end
Do I do something wrong?
Thank you
Sidekiq's internal retry mechanism is not designed for application access, otherwise there would be a thousand configuration knobs for every dev who wanted to customize every aspect of it. If your app has custom error handling and notification logic, you need to build it in your app code.
https://github.com/mperham/sidekiq/wiki/Error-Handling#no-more-bike-shedding
@palexvs maybe you could pass the current time as one of the arguments to your worker and send the notification if sufficient time has passed rather than counting retries?
Most helpful comment
@mperham is there any reason do not give access to the
retry_count?I found a few workarounds (1 and 2) but I don't understand why
retry_countis not a part of standard APII use Sidekiq to deliver
web_hooksto clients and if someweb_hookfails the delivery should be retried 30 times (for 60 days). But I want to notify a client about the issue starting from 5th attempt (don't bother the client if he has a short downtime) and I would expect something like this:Do I do something wrong?
Thank you