1
0
Fork 0
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:
Thorsten Ball 2013-03-09 18:19:17 +01:00
parent dfc7e35b11
commit e72cfe0841

View file

@ -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
require 'yaml'
@ -48,6 +37,14 @@ module Sidekiq
end
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 "Running in #{RUBY_DESCRIPTION}"
logger.info Sidekiq::LICENSE
@ -69,7 +66,7 @@ module Sidekiq
end
launcher.run
while readable_io = IO.select([$self_read])
while readable_io = IO.select([self_read])
signal = readable_io.first[0].gets.strip
handle_signal(signal)
end
@ -82,6 +79,8 @@ module Sidekiq
end
end
private
def handle_signal(sig)
Sidekiq.logger.debug "Got #{sig} signal"
case sig
@ -119,8 +118,6 @@ module Sidekiq
end
end
private
def load_celluloid
raise "Celluloid cannot be required until here, or it will break Sidekiq's daemonization" if defined?(::Celluloid) && options[:daemon]