How to delete Sidekiq Enterprise periodic jobs?

十年热恋 提交于 2020-07-11 04:34:39

问题


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?


回答1:


The Sidekiq Enterprise leader role was held by a secondary server. When the leader role is held the Periodic Jobs are locked and cannot be modified. Shut down all Sidekiq servers, including the leader, and then restart Sidekiq to purge and re-register all jobs from the initializer.

There is no need to use the API to delete Periodic Jobs.




回答2:


Just run this:

Sidekiq::Cron::Job.destroy_all!

As described in sidekiq-cron docs



来源:https://stackoverflow.com/questions/36876565/how-to-delete-sidekiq-enterprise-periodic-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!