Class: Whoosh::Shutdown
- Inherits:
-
Object
- Object
- Whoosh::Shutdown
- Defined in:
- lib/whoosh/shutdown.rb
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(logger: nil) ⇒ Shutdown
constructor
A new instance of Shutdown.
- #install_signal_handlers! ⇒ Object
- #register(&block) ⇒ Object
Constructor Details
#initialize(logger: nil) ⇒ Shutdown
Returns a new instance of Shutdown.
5 6 7 8 9 |
# File 'lib/whoosh/shutdown.rb', line 5 def initialize(logger: nil) @hooks = [] @logger = logger @executed = false end |
Instance Method Details
#execute! ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/whoosh/shutdown.rb', line 15 def execute! return if @executed @executed = true @hooks.reverse_each do |hook| hook.call rescue => e @logger&.error("shutdown_hook_error", message: e.) end end |
#install_signal_handlers! ⇒ Object
25 26 27 28 |
# File 'lib/whoosh/shutdown.rb', line 25 def install_signal_handlers! trap("TERM") { execute! } trap("INT") { execute! } end |
#register(&block) ⇒ Object
11 12 13 |
# File 'lib/whoosh/shutdown.rb', line 11 def register(&block) @hooks << block end |