Class: Gouda::TrapShutdownCheck
- Inherits:
-
Object
- Object
- Gouda::TrapShutdownCheck
- Defined in:
- lib/gouda/worker.rb
Overview
Captures UNIX signals (TERM and INT) and then returns true. Once you initialize the this check you install signal handlers, meaning that the worker will not raise ‘Interrupt` from any theads but will get the space it needs to terminate cleanly. At least for SIGINT and SIGTERM this is very desirable. This is the default shutdown check.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize ⇒ TrapShutdownCheck
constructor
A new instance of TrapShutdownCheck.
Constructor Details
#initialize ⇒ TrapShutdownCheck
Returns a new instance of TrapShutdownCheck.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gouda/worker.rb', line 52 def initialize @did_trap = false @did_log = false Signal.trap(:TERM) do @did_trap = :TERM end Signal.trap(:INT) do @did_trap = :INT end end |
Instance Method Details
#call ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gouda/worker.rb', line 63 def call if @did_trap @did_log ||= begin warn("Gouda worker signaled to terminate via SIG#{@did_trap}") true end true else false end end |