Sha256: ef32231296894e87795fed00eef1924865a12b885b3ebab214bcf3c4ad033160
Contents?: true
Size: 1.14 KB
Versions: 5
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module Delayed module Master class Signaler SIGNAL_HANDLERS = [ [:TERM, :stop], [:INT, :stop], [:QUIT, :quit], [:WINCH, :graceful_stop], [:USR1, :reopen_files], [:USR2, :restart] ] def initialize(master) @master = master end def register SIGNAL_HANDLERS.each do |signal, method| register_signal(signal, method) end end def dispatch(signal) @master.workers.each do |worker| next unless worker.pid dispatch_to(signal, worker.pid) end end private def register_signal(signal, method) Signal.trap(signal) do Thread.new do @master.logger.info { "received #{signal} signal" } @master.public_send(method) end end end def dispatch_to(signal, pid) Process.kill(signal, pid) @master.logger.info { "sent #{signal} signal to worker #{pid}" } rescue @master.logger.error { "failed to send #{signal} signal to worker #{pid}" } end end end end
Version data entries
5 entries across 5 versions & 1 rubygems