class Osbourne::Runner
Public Instance Methods
run()
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/osbourne/runner.rb, line 16 def run self_read, self_write = IO.pipe %w[INT TERM USR1 TSTP TTIN].each do |sig| begin trap sig do self_write.puts(sig) end rescue ArgumentError puts "Signal #{sig} not supported" end end @launcher = Osbourne::Launcher.new begin Osbourne.provision_worker_queues @launcher.start! while readable_io = IO.select([self_read]) # rubocop:disable Lint/AssignmentInCondition signal = readable_io.first[0].gets.strip handle_signal(signal) end @launcher.wait! rescue Interrupt @launcher.stop! exit 0 end end
Private Instance Methods
execute_soft_shutdown()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/osbourne/runner.rb, line 49 def execute_soft_shutdown Osbourne.logger.info { "[Osbourne] Received USR1, will soft shutdown down" } @launcher.stop exit 0 end
execute_terminal_stop()
click to toggle source
# File lib/osbourne/runner.rb, line 56 def execute_terminal_stop Osbourne.logger.info { "[Osbourne] Received TSTP, will stop accepting new work" } @launcher.stop! end
handle_signal(sig)
click to toggle source
# File lib/osbourne/runner.rb, line 73 def handle_signal(sig) Osbourne.logger.debug "[Osbourne] Got #{sig} signal" case sig when "USR1" then execute_soft_shutdown when "TTIN" then print_threads_backtrace when "TSTP" then execute_terminal_stop when "TERM", "INT" Osbourne.logger.info { "[Osbourne] Received #{sig}, will shutdown" } raise Interrupt end end
print_threads_backtrace()
click to toggle source
# File lib/osbourne/runner.rb, line 62 def print_threads_backtrace Thread.list.each do |thread| Osbourne.logger.info { "[Osbourne] Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}" } if thread.backtrace Osbourne.logger.info { thread.backtrace.join("\n") } else Osbourne.logger.info { "[Osbourne] <no backtrace available>" } end end end