Skip to content

Commit

Permalink
Allow TERM to follow a USR1 by not blocking the main thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhyman committed Dec 10, 2013
1 parent de65b2e commit 0429104
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
14 changes: 4 additions & 10 deletions lib/sidekiq/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Sidekiq
# DO NOT RESCUE THIS ERROR.
class Shutdown < Interrupt; end

class USR1Interrupt < Interrupt; end

class CLI
include Util
include Singleton
Expand Down Expand Up @@ -76,22 +78,14 @@ def run
end
rescue USR1Interrupt
logger.info 'Stopping work, will shut down when workers finish'
stop(false)
launcher.async.stop(false)
rescue Interrupt
logger.info 'Shutting down'
stop
launcher.async.stop
end
end

private

def stop(force_shutdown_after_timeout = true)
launcher.stop(force_shutdown_after_timeout)
# Explicitly exit so busy Processor threads can't block
# process shutdown.
exit(0)
end

def handle_signal(sig)
Sidekiq.logger.debug "Got #{sig} signal"
case sig
Expand Down
2 changes: 2 additions & 0 deletions lib/sidekiq/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def stop(force_shutdown_after_timeout = true)
manager.async.stop(opts)
manager.wait(:shutdown)
end

exit(0)
end

def procline(tag)
Expand Down
5 changes: 0 additions & 5 deletions lib/sidekiq/usr1_interrupt.rb

This file was deleted.

0 comments on commit 0429104

Please sign in to comment.