Skip to content

Instantly share code, notes, and snippets.

@nkwhr
Created May 1, 2015 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkwhr/e06be3b1e12eea14bbd7 to your computer and use it in GitHub Desktop.
Save nkwhr/e06be3b1e12eea14bbd7 to your computer and use it in GitHub Desktop.
Safely stop Sidekiq process
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