From the Rails API, I found ActiveJob can retry_job interval:
my_job_instance.enqueue
my_job_instance.enqueue wait: 5.minutes
my_job_instance.enqueue queue: :important
my_job_instance.enqueue wait_until: Date.tomorrow.midnight
But if I want to set retry count, such as Sidekiq's:
include Sidekiq::Worker
sidekiq_options :retry => 5
How to do in this sample code?
class SiteScrapperJob < ActiveJob::Base
rescue_from(ErrorLoadingSite) do
retry_job queue: :low_priority
end
def perform(*args)
# raise ErrorLoadingSite if cannot scrape
end
end
Now I added this to my job class:
Sidekiq.default_worker_options = { retry: 5 }
But it seems not very good.
As of Sidekiq 6.0.4 you can use sidekiq_options
in an ActiveJob to set the retry
option.