How do I force retrying Sidekiq jobs stuck in the retry queue?

51 Views Asked by At

I have a lot of jobs clogging up the retry queue in Sidekiq, with a high latency. For some reason they are not worked on, and I cannot find a way to directly schedule the retry of these jobs from the retry queue itself.

How would I go about doing that, essentially force-retrying all of them?

1

There are 1 best solutions below

0
slhck On

There seems to be no way to do this directly. Retried jobs whose retries are exhausted should eventually go to the DeadSet. First collect the retried jobs and their arguments:

require 'sidekiq/api'
jobs = Sidekiq::Queue.new("retries").map { |j| [j.klass, j.args] }
# => e.g.:
#  ["MyWorker", [125396, "some_arg"]],
#  ["MyWorker", [125394, "some_arg"]],
#  ["MyWorker", [125395, "some_arg"]],
#  ["MyWorker", [98761, "another_arg"]],
#  ["MyWorker", [98760, "another_arg"]],
#  ["MyWorker", [41624, "another_arg"]],
#  ["MyWorker", [41623, "another_arg"]],
#  ["MyWorker", [32164, "another_arg"]],
#  ["MyWorker", [32167, "some_arg"]],
#  ["MyWorker", [32165, "another_arg"]],
#  ["MyWorker", [31870, "some_arg"]],
#  ["MyWorker", [31871, "some_arg"]]]

Now, schedule an immediate retry for each job:

jobs.each do |job|
  klass = job[0].constantize
  args = job[1]
  klass.perform_async(*args)
end

Finally, we clear the retry queue:

Sidekiq::Queue.new("retries").clear