Created
May 1, 2015 06:25
-
-
Save nkwhr/e06be3b1e12eea14bbd7 to your computer and use it in GitHub Desktop.
Safely stop Sidekiq process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sidekiq/api' | |
namespace :sidekiq do | |
task 'stop' do | |
ps = Sidekiq::ProcessSet.new | |
abort 'Sidekiq process not running' if ps.count == 0 | |
ps.first.quiet! | |
puts "SIGUSR1 sent\nWaiting 10sec for status update" | |
sleep 10 | |
while (running_tasks = ps.first['busy']) > 0 | |
puts "Waiting for tasks to finish. Num tasks: #{running_tasks}" | |
sleep 5 | |
end | |
ps.first.stop! | |
puts 'SIGTERM sent' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment