Trying to program a job that after 10 retries (from all exception types) will report a failure and die. Can't get it to work. Tried this answer and this one too. Neither worked.
The best solution would be to access retry_count
from within the perform
method.
Asked
Active
Viewed 1,642 times
2

Yossi Shasho
- 3,632
- 31
- 47
1 Answers
1
I think what you're asking for is the sidekiq_retries_exhausted
hook. It will be called once your retries are up and job will move to dead queue. Just set retries to 10 and implement that hook.
config.death_handlers
might also be interesting.
See docs here: https://github.com/mperham/sidekiq/wiki/Error-Handling#configuration

Siim Liiser
- 3,860
- 11
- 13
-
Does that work with the ActiveJob? I don't use `include Sidekiq::Worker` – Yossi Shasho Jul 26 '20 at 15:00
-
It seems to me that the solution you need is from the same thread that you already looked at, but the one you didn't try (https://stackoverflow.com/a/48302041/4473406) using retry_on https://stackoverflow.com/a/48302041/4473406. You can retry_on StandardError to catch all exceptions and pass a block that will be called once the retries are up. If you want the job to end up in the dead queue, then re-raise the error from the block and set retry to false on sidekiq level. Let me know if you'd like me to edit my answer. – Siim Liiser Jul 27 '20 at 08:06
-
retry_on StandardError is a good idea! I'll give it a shot. thank you – Yossi Shasho Jul 28 '20 at 11:49