21

I have jobs of a particular type that I'd like to have retry more frequently than set by the default Sidekiq interval. Is this currently possible? Ideally the job would retry every 5 seconds for up to a minute. Not entirely sure this is currently something that's trivial to plugin to a Sidekiq job.

randombits
  • 47,058
  • 76
  • 251
  • 433

3 Answers3

33

According to: https://github.com/mperham/sidekiq/wiki/Error-Handling you can do this:

class Worker
  include Sidekiq::Worker

  sidekiq_retry_in do |count|
    5
  end
end
Bart
  • 2,606
  • 21
  • 32
1

If you need other range, can use minute syntax

sidekiq_retry_in do |_count|
  10.minutes
end
CHBLU
  • 11
  • 2
1

I'm answering if calling 10.minutes in the block works, because I can't comment on an answer.

According to the Sidekiq code, you need to pass an Integer, or either :kill or :discard symbols.

10.minutes returns an instance of ActiveSupport::Duration

This means that the following would work:

class Worker
  include Sidekiq::Worker

  sidekiq_retry_in { 10.minutes.to_i }
end

Source

antonpot
  • 41
  • 9
  • In sidekiq 7 this has been fixed (https://github.com/sidekiq/sidekiq/issues/5806), durations should now work as before – RMK Feb 27 '23 at 15:09