Last active
June 16, 2017 05:25
-
-
Save ikuradon/f10a9fb43d05bbc75545cac49a8f672c to your computer and use it in GitHub Desktop.
Sidekiqを安全に停止させるRailsタスク
This file contains 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
namespace :sidekiq do | |
desc "Stop sidekiq safely." | |
task :stop do | |
processes = Sidekiq::ProcessSet.new | |
abort 'Sidekiq process not running' if processes.count == 0 | |
processes.each do |process| | |
process.quiet! | |
puts "Send quiet signal to PID: #{process['pid']}" | |
end | |
puts 'Waiting 10 sec for status update...' | |
sleep 10 | |
processes.each do |process| | |
while (running_tasks = process['busy']) > 0 | |
puts "Waiting for tasks to finish. PID: #{process['pid']}, Num tasks: #{running_tasks}" | |
sleep 5 | |
end | |
process.stop! | |
puts "Send stop signal to PID: #{process['pid']}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment