Retry sidekiq job if it is in dead queue in rails

2.4k Views Asked by At

I want to write a cron job which fetches the sidekiq job from the dead queue and retry it, as we can do it from sidekiq's Web UI, I want to do the same through the code.

1

There are 1 best solutions below

3
Schwern On

The dead queue is accessed with Sidekiq::DeadSet which has a retry_all method.

Sidekiq::DeadSet.new.retry_all

This is a thin wrapper around iterating over each job in the queue and calling retry. SideKiq::DeadSet is Enumerable so you can use methods like select and each. The wiki page has a good example.

ds = Sidekiq::DeadSet.new

# Retry only jobs of FixedWorker class whose first argument is 123.
ds.select { |job|
  job.klass == 'FixedWorker' && job.args[0] == 123
}.map(&:retry)