Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

ruby on rails - How to delete Sidekiq Enterprise periodic jobs?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...