Class: SignalHandler

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeSignalHandler

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_quitObject (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_signalObject



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