Search code examples
ruby-on-railssidekiq

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


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?


Solution

  • 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::RetrySet.new
    jobs.each do |job|
      puts "[#{job.klass}, #{job.args}]"
    end and nil
    # => 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|
      job.klass.constantize.perform_async(*job.args)
    end
    

    Finally, we clear the retry queue:

    Sidekiq::RetrySet.new.clear