Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...