简体   繁体   中英

How to kill Sidekiq worker?

I've got an application that after each deploy needs to kill specific Sidekiq worker. As it's api suggests I can do it by removing all jobs from queue Sidekiq::Queue.new.clear .

However, after running this command the number of worker sizes Sidekiq::Workers.new.size still the same. Actually, I've tried a lot of methods but nothing works. Please, help!

I haven't tried it myself, but based on the documentation:

You could add all the workers meant to be deleted as part of a queue (eg. post_deploy)

class MyWorker
  include Sidekiq::Worker
  sidekiq_options :retry => 5, :dead => false, queue: :post_deploy

  def perform()
  ...
  end
end

For deleting the workers:

require 'sidekiq/api'
Sidekiq::Queue.new("post_deploy").clear

To find the number of jobs under the queue, you need to find it this way

Sidekiq::Queue.new("post_deploy").size

Only to find number of Sidekiq threads that are currently running, you will be using Sidekiq::Worker.size

Let me know if I have misunderstood your question.

Once a worker has started processing a job, you cannot stop it externally without shutting down the entire process. There is no safe way to stop a thread.

You can add the ability to stop a worker to your own code by having the worker code check regularly to see if it should stop, similar to job cancellation .

Short answer. Kill your process. and run this.

Sidekiq::Queue.new("default").clear

"default" is your queue name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM