Sidekiq Enterprise includes support for Periodic Jobs and includes an example of using the initializer to register jobs:
Sidekiq.configure_server do |config|
config.periodic do |mgr|
# see any crontab reference for the first argument
# e.g. http://www.adminschoice.com/crontab-quick-reference
mgr.register('0 * * * *', SomeHourlyWorkerClass)
mgr.register('* * * * *', SomeWorkerClass, retry: 2, queue: 'foo')
mgr.register(cron_expression, worker_class, job_options={})
end
end
After registering a job, how does one delete/unregister a job? For example, if the worker is no longer used and should not run anymore how do you safely remove the registered job from Redis? Removing it from the initializer and restarting Sidekiq doesn't do it, and the API doesn't appear to offer deletion, instead saying The Periodic API allows you to list registered periodic jobs and see enqueue history.
There is an API for deleting jobs in a regular queue:
queue = Sidekiq::Queue.new("mailer")
queue.each do |job|
job.klass # => 'MyWorker'
job.args # => [1, 2, 3]
job.delete if job.jid == 'abcdef1234567890'
end
But attempting to adapt this for the periodic jobs API:
Sidekiq::Periodic::LoopSet.new.each do |lop|
lop.delete
end
...raises an error:
NoMethodError: undefined method `delete' for #<Sidekiq::Periodic::Loop:0x007fff0a48dbe8>
The Redis db shows that Sidekiq has created a loop-uniqueid
key for each loop, as well as a loop-history-uniqueid
key and loops-uniqueid
key. Should I destroy all of these keys? Is it best to destroy all these keys and then re-register all current jobs?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…