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
|
trap 'INT' do
|
||||||
# Handle Ctrl-C in JRuby like MRI
|
# Handle Ctrl-C in JRuby like MRI
|
||||||
# http://jira.codehaus.org/browse/JRUBY-4637
|
# http://jira.codehaus.org/browse/JRUBY-4637
|
||||||
Thread.main.raise Interrupt
|
Sidekiq::CLI.instance.interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
trap 'TERM' do
|
trap 'TERM' do
|
||||||
# Heroku sends TERM and then waits 10 seconds for process to exit.
|
# Heroku sends TERM and then waits 10 seconds for process to exit.
|
||||||
Thread.main.raise Interrupt
|
Sidekiq::CLI.instance.interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
trap 'USR1' do
|
trap 'USR1' do
|
||||||
|
@ -43,6 +43,8 @@ module Sidekiq
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@code = nil
|
@code = nil
|
||||||
|
@interrupt_mutex = Mutex.new
|
||||||
|
@interrupted = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(args=ARGV)
|
def parse(args=ARGV)
|
||||||
|
@ -80,6 +82,15 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def interrupt
|
||||||
|
@interrupt_mutex.synchronize do
|
||||||
|
unless @interrupted
|
||||||
|
@interrupted = true
|
||||||
|
Thread.main.raise Interrupt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def die(code)
|
def die(code)
|
||||||
|
|
Loading…
Reference in a new issue