Replies: 4 comments
-
Nothing's stopping you from building this yourself. Add a Module to Sidekiq::Job which adds a class method, something like: # in config/initializers/sidekiq.rb
module MyJobUtils
def for(seconds)
secs = seconds.to_i
case secs
when 0..10: 1
when 10..100: 2
when 100..1000: 3
when 1000..10_000: 4
else
5
end
end
end
Sidekiq::Job.send(:extend, MyJobUtils) # in each job class
class MyJob
include Sidekiq::Job
sidekiq_options retry: for(5.minutes)
end Something like that. Code hasn't been tested but that should get you 95% there. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestion, I am trying to extend as suggested but I am having a hard time: module RetryStrategy
class << self
def method1
end
end
def self.method2
end
def method3
end
end
Sidekiq::JobUtil.send(:extend, RetryStrategy)
Sidekiq::Job.send(:extend, RetryStrategy)
Sidekiq::Worker.send(:extend, RetryStrategy) Then in a worker: class FooWorker
include Sidekiq::Worker
pp methods - Object.methods
end And then running ❯ bundle exec rails console
[:sidekiq_retry_in_block,
:sidekiq_options_hash,
:sidekiq_options_hash=,
:sidekiq_retry_in_block=,
:sidekiq_retries_exhausted_block,
:sidekiq_retries_exhausted_block=,
:queue_as,
:set,
:sidekiq_options,
:delay,
:perform_async,
:perform_inline,
:client_push,
:perform_in,
:perform_bulk,
:perform_at,
:delay_for,
:delay_until,
:get_sidekiq_options,
:sidekiq_retry_in,
:sidekiq_class_attribute,
:sidekiq_retries_exhausted] Maybe the only way to do that is by having another class I do |
Beta Was this translation helpful? Give feedback.
-
Monkeypatching the ClassMethods should work. module Sidekiq::Worker::Options::ClassMethods
def for(...)
...
end
end |
Beta Was this translation helpful? Give feedback.
-
Not sure how to close a discussion but yeah, I wasn't able to get this working. It was fun to try though. |
Beta Was this translation helpful? Give feedback.
-
Hello, 👋
I've been using Sidekiq for years both paid and free versions. Thank you Mike for your current and future contributions.
One common need I have with Sidekiq is setting the retry option for some specific workers. Example:
My workflow for finding the correct number of retries usually looks like:
# ~5 minutes
It would be lovely to be able to set it the number of retries based on a estimated total waiting time. For example:
This would remove the need to use that guide table as a reference.
Thank you for considering this idea.
Beta Was this translation helpful? Give feedback.
All reactions