mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Do not use globals for signal handling
This moves the trapping and handling of signals into `Sidekiq::CLI#run`, so no more global self-pipe is necessary.
This commit is contained in:
parent
dfc7e35b11
commit
e72cfe0841
1 changed files with 11 additions and 14 deletions
|
@ -1,14 +1,3 @@
|
||||||
$self_read, $self_write = IO.pipe
|
|
||||||
|
|
||||||
# Signal handlers should do as little as humanly possible
|
|
||||||
# and defer all work to a non-trap context. We'll have
|
|
||||||
# the main thread poll for signals and handle them there.
|
|
||||||
%w(INT TERM USR1 USR2 TTIN).each do |sig|
|
|
||||||
trap sig do
|
|
||||||
$self_write.puts(sig)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
$stdout.sync = true
|
$stdout.sync = true
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
@ -48,6 +37,14 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
|
self_read, self_write = IO.pipe
|
||||||
|
|
||||||
|
%w(INT TERM USR1 USR2 TTIN).each do |sig|
|
||||||
|
trap sig do
|
||||||
|
self_write.puts(sig)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
logger.info "Booting Sidekiq #{Sidekiq::VERSION} with Redis at #{redis {|x| x.client.id}}"
|
logger.info "Booting Sidekiq #{Sidekiq::VERSION} with Redis at #{redis {|x| x.client.id}}"
|
||||||
logger.info "Running in #{RUBY_DESCRIPTION}"
|
logger.info "Running in #{RUBY_DESCRIPTION}"
|
||||||
logger.info Sidekiq::LICENSE
|
logger.info Sidekiq::LICENSE
|
||||||
|
@ -69,7 +66,7 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
launcher.run
|
launcher.run
|
||||||
|
|
||||||
while readable_io = IO.select([$self_read])
|
while readable_io = IO.select([self_read])
|
||||||
signal = readable_io.first[0].gets.strip
|
signal = readable_io.first[0].gets.strip
|
||||||
handle_signal(signal)
|
handle_signal(signal)
|
||||||
end
|
end
|
||||||
|
@ -82,6 +79,8 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def handle_signal(sig)
|
def handle_signal(sig)
|
||||||
Sidekiq.logger.debug "Got #{sig} signal"
|
Sidekiq.logger.debug "Got #{sig} signal"
|
||||||
case sig
|
case sig
|
||||||
|
@ -119,8 +118,6 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def load_celluloid
|
def load_celluloid
|
||||||
raise "Celluloid cannot be required until here, or it will break Sidekiq's daemonization" if defined?(::Celluloid) && options[:daemon]
|
raise "Celluloid cannot be required until here, or it will break Sidekiq's daemonization" if defined?(::Celluloid) && options[:daemon]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue