Skip to content

Commit

Permalink
Manager now fires stop-related events
Browse files Browse the repository at this point in the history
Gives more fine-grained control as to when the actual event fires.  We also give a small bit of time for the event processors to take effect for those handlers with asynchronous side effects (like shutting down other threads and subsystems).
  • Loading branch information
mperham committed Oct 30, 2015
1 parent 6698bdc commit 8ffdb36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/sidekiq/cli.rb
Expand Up @@ -97,7 +97,6 @@ def run
rescue Interrupt
logger.info 'Shutting down'
launcher.stop
fire_event(:shutdown, true)
# Explicitly exit so busy Processor threads can't block
# process shutdown.
exit(0)
Expand Down Expand Up @@ -134,7 +133,6 @@ def handle_signal(sig)
when 'USR1'
Sidekiq.logger.info "Received USR1, no longer accepting new work"
launcher.quiet
fire_event(:quiet, true)
when 'USR2'
if Sidekiq.options[:logfile]
Sidekiq.logger.info "Received USR2, reopening log file"
Expand Down
7 changes: 7 additions & 0 deletions lib/sidekiq/manager.rb
Expand Up @@ -52,10 +52,17 @@ def quiet

logger.info { "Terminating quiet workers" }
@workers.each { |x| x.terminate }
fire_event(:quiet, true)
end

def stop(deadline)
quiet
fire_event(:shutdown, true)

# some of the shutdown events can be async,
# we don't have any way to know when they're done but
# give them a little time to take effect
sleep 0.5
return if @workers.empty?

logger.info { "Pausing to allow workers to finish..." }
Expand Down

0 comments on commit 8ffdb36

Please sign in to comment.