Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get sidekiq retry_count from inside a job

I am trying to send an alert every time retry_count of a sidekiq job reaches 5(to warn an engineer to check why the worker is failing) and then continued being retried as usual.

Is there a way to get the retry count for a particular job from inside the job?

I could just use:

sidekiq_retry_in do |count|
  (warn engineer here)
  10 * (count + 1) # (i.e. 10, 20, 30, 40)
end

and send a message from in there, but I think its a bit of a hack.

Any ideas? googling didn't surface any results.

like image 976
Totic Avatar asked Jul 10 '15 19:07

Totic


People also ask

How do you stop a Sidekiq worker?

Once a worker has started processing a job, you cannot stop it externally without shutting down the entire process. There is no safe way to stop a thread.

How do I manually run a Sidekiq job?

To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.

How do I get a job on Sidekiq?

To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.


1 Answers

There is no way to get the retry count from within the job, by design.

like image 111
Mike Perham Avatar answered Oct 24 '22 19:10

Mike Perham