mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Gracefully handle receipt of multiple termination signals
This commit is contained in:
parent
e58406bd97
commit
7be3102865
1 changed files with 13 additions and 2 deletions
|
@ -1,12 +1,12 @@
|
|||
trap 'INT' do
|
||||
# Handle Ctrl-C in JRuby like MRI
|
||||
# http://jira.codehaus.org/browse/JRUBY-4637
|
||||
Thread.main.raise Interrupt
|
||||
Sidekiq::CLI.instance.interrupt
|
||||
end
|
||||
|
||||
trap 'TERM' do
|
||||
# Heroku sends TERM and then waits 10 seconds for process to exit.
|
||||
Thread.main.raise Interrupt
|
||||
Sidekiq::CLI.instance.interrupt
|
||||
end
|
||||
|
||||
trap 'USR1' do
|
||||
|
@ -43,6 +43,8 @@ module Sidekiq
|
|||
|
||||
def initialize
|
||||
@code = nil
|
||||
@interrupt_mutex = Mutex.new
|
||||
@interrupted = false
|
||||
end
|
||||
|
||||
def parse(args=ARGV)
|
||||
|
@ -80,6 +82,15 @@ module Sidekiq
|
|||
end
|
||||
end
|
||||
|
||||
def interrupt
|
||||
@interrupt_mutex.synchronize do
|
||||
unless @interrupted
|
||||
@interrupted = true
|
||||
Thread.main.raise Interrupt
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def die(code)
|
||||
|
|
Loading…
Reference in a new issue