Class: SignalHandler
- Inherits:
-
Object
- Object
- SignalHandler
- Includes:
- Singleton
- Defined in:
- lib/signal_handler.rb
Overview
Singleton class used to intercept signals. If a SIGINT or SIGTERM is received a message is outputted and @should_quit is set to true
Instance Attribute Summary collapse
-
#should_quit ⇒ Object
readonly
Returns the value of attribute should_quit.
Instance Method Summary collapse
- #handle_signal ⇒ Object
-
#initialize ⇒ SignalHandler
constructor
A new instance of SignalHandler.
Constructor Details
#initialize ⇒ SignalHandler
Returns a new instance of SignalHandler.
14 15 16 17 18 |
# File 'lib/signal_handler.rb', line 14 def initialize @should_quit = false Signal.trap("SIGINT") { handle_signal } Signal.trap("SIGTERM") { handle_signal } end |
Instance Attribute Details
#should_quit ⇒ Object (readonly)
Returns the value of attribute should_quit.
7 8 9 |
# File 'lib/signal_handler.rb', line 7 def should_quit @should_quit end |
Instance Method Details
#handle_signal ⇒ Object
9 10 11 12 |
# File 'lib/signal_handler.rb', line 9 def handle_signal puts "PID #{Process.pid} is gracefully shutting down..." @should_quit = true end |