Class: QueueKit::SignalChecker
- Inherits:
-
Object
- Object
- QueueKit::SignalChecker
- Defined in:
- lib/queue_kit/signal_checker.rb
Constant Summary collapse
- COMMON_SIGNALS =
%w(TERM INT)
- JRUBY_SIGNALS =
%w(QUIT USR1)
- OPTIONAL_SIGNALS =
%w(USR2 CONT HUP)
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Class Method Summary collapse
Instance Method Summary collapse
- #debug(key, sig) ⇒ Object
-
#initialize(worker, handler) ⇒ SignalChecker
constructor
A new instance of SignalChecker.
- #trap_signal(sig) ⇒ Object
- #trap_signals(signals = nil) ⇒ Object
Constructor Details
#initialize(worker, handler) ⇒ SignalChecker
Returns a new instance of SignalChecker.
14 15 16 17 |
# File 'lib/queue_kit/signal_checker.rb', line 14 def initialize(worker, handler) @worker = worker @handler = handler end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
8 9 10 |
# File 'lib/queue_kit/signal_checker.rb', line 8 def handler @handler end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
7 8 9 |
# File 'lib/queue_kit/signal_checker.rb', line 7 def worker @worker end |
Class Method Details
.trap(worker, handler) ⇒ Object
10 11 12 |
# File 'lib/queue_kit/signal_checker.rb', line 10 def self.trap(worker, handler) new(worker, handler).trap_signals end |
Instance Method Details
#debug(key, sig) ⇒ Object
44 45 46 |
# File 'lib/queue_kit/signal_checker.rb', line 44 def debug(key, sig) @worker.debug { ["signals.#{key}", {:signal => sig}] } end |
#trap_signal(sig) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/queue_kit/signal_checker.rb', line 32 def trap_signal(sig) trap_method = "trap_#{sig}" return unless @handler.respond_to?(trap_method) debug :setup, sig old_handler = trap sig do @handler.send(trap_method, @worker) old_handler.call if old_handler.respond_to?(:call) end end |
#trap_signals(signals = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/queue_kit/signal_checker.rb', line 19 def trap_signals(signals = nil) if signals.nil? trap_signals(COMMON_SIGNALS) trap_signals(JRUBY_SIGNALS) unless defined?(JRUBY_VERSION) trap_signals(OPTIONAL_SIGNALS) else signals.each { |sig| trap_signal(sig) } end rescue ArgumentError warn "Signals are not supported: #{signals.inspect}" end |