1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Switch default quiet signal to TSTP as it is available on JRuby, fixes #3302 (#3302)

This commit is contained in:
Mike Perham 2017-01-03 15:24:48 -08:00 committed by GitHub
parent 064cd3304d
commit 6a8e1e0702
6 changed files with 20 additions and 12 deletions

View file

@ -748,7 +748,7 @@ module Sidekiq
end
def quiet!
signal('USR1')
signal('TSTP')
end
def stop!

View file

@ -43,6 +43,10 @@ module Sidekiq
write_pid
end
def jruby?
defined?(::JRUBY_VERSION)
end
# Code within this method is not tested because it alters
# global process state irreversibly. PRs which improve the
# test coverage of Sidekiq::CLI are welcomed.
@ -51,8 +55,14 @@ module Sidekiq
print_banner
self_read, self_write = IO.pipe
sigs = %w(INT TERM TTIN TSTP)
# USR1 and USR2 don't work on the JVM
if !jruby?
sigs << 'USR1'
sigs << 'USR2'
end
%w(INT TERM USR1 USR2 TTIN).each do |sig|
sigs.each do |sig|
begin
trap sig do
self_write.puts(sig)
@ -135,6 +145,10 @@ module Sidekiq
when 'USR1'
Sidekiq.logger.info "Received USR1, no longer accepting new work"
launcher.quiet
when 'TSTP'
# USR1 is not available on JVM, allow TSTP as an alternate signal
Sidekiq.logger.info "Received TSTP, no longer accepting new work"
launcher.quiet
when 'USR2'
if Sidekiq.options[:logfile]
Sidekiq.logger.info "Received USR2, reopening log file"

View file

@ -61,8 +61,6 @@ module Sidekiq
private unless $TESTING
JVM_RESERVED_SIGNALS = ['USR1', 'USR2'] # Don't Process#kill if we get these signals via the API
def heartbeat
results = Sidekiq::CLI::PROCTITLES.map {|x| x.(self, to_data) }
results.compact!
@ -110,11 +108,7 @@ module Sidekiq
return unless msg
if JVM_RESERVED_SIGNALS.include?(msg)
Sidekiq::CLI.instance.handle_signal(msg)
else
::Process.kill(msg, $$)
end
::Process.kill(msg, $$)
rescue => e
# ignore all redis/network issues
logger.error("heartbeat: #{e.message}")

View file

@ -436,7 +436,7 @@ class TestApi < Sidekiq::Test
data.stop!
signals_string = "#{odata['key']}-signals"
assert_equal "TERM", Sidekiq.redis{|c| c.lpop(signals_string) }
assert_equal "USR1", Sidekiq.redis{|c| c.lpop(signals_string) }
assert_equal "TSTP", Sidekiq.redis{|c| c.lpop(signals_string) }
end
it 'can enumerate workers' do

View file

@ -351,7 +351,7 @@ class TestCli < Sidekiq::Test
count += 1
}]
@cli.launcher = Sidekiq::Launcher.new(Sidekiq.options)
@cli.handle_signal('USR1')
@cli.handle_signal('TSTP')
assert_equal 1, count
end

View file

@ -81,7 +81,7 @@ class TestWeb < Sidekiq::Test
assert_nil Sidekiq.redis { |c| c.lpop signals_key }
post '/busy', 'quiet' => '1', 'identity' => identity
assert_equal 302, last_response.status
assert_equal 'USR1', Sidekiq.redis { |c| c.lpop signals_key }
assert_equal 'TSTP', Sidekiq.redis { |c| c.lpop signals_key }
end
it 'can stop a process' do