0

When a job in Sidekiq fails, it goes into retry queue and it is retried for 25 times, as per https://github.com/mperham/sidekiq/wiki/Error-Handling#automatic-job-retry. So the question is, Is there any way to find whether the job that is currently getting executed, is running for first-time or it is the n'th retry of that job?

Note this job is running separately in a worker.

P.s: I'm new to sidekiq, workers and async jobs, so pardon if the question is not clear or an obvious one.

Learn-ing
  • 21
  • 2
  • 2
    Short answer "you can't". Long answer: there is no built-in way to get the retry count within the job itself - retry machinery is kind of orthogonal to the jobs themselves. You could hack around jobs retry middleware maybe, but may I ask why do you need this counter? – Konstantin Strukov Dec 15 '22 at 12:31
  • This sounds like a xy problem to me. Why do you need to know if a job is retried and how other? – spickermann Dec 15 '22 at 12:36
  • I have a system, where we send notification when the job fails for the first time but we shouldn't send the same notification whenever we retry and the job fails. Also thanks for the answer. – Learn-ing Dec 16 '22 at 05:14
  • This sounds quite controversial. Depending on the transport layer, the notification about job failure might arrive _after the job was successfully retried_ - in this case it will be absolutely misleading and can cause wrong actions. – Konstantin Strukov Dec 16 '22 at 09:44
  • You can simply catch the exception in perform method and register the failure/retry in the database. – tejasbubane Jan 02 '23 at 22:29

0 Answers0