Class: Gorgon::PingService
- Inherits:
-
Object
- Object
- Gorgon::PingService
- Includes:
- Configuration
- Defined in:
- lib/gorgon/ping_service.rb
Constant Summary collapse
- TIMEOUT =
4
Instance Method Summary collapse
-
#initialize ⇒ PingService
constructor
A new instance of PingService.
- #ping_listeners ⇒ Object
Methods included from Configuration
Constructor Details
#initialize ⇒ PingService
Returns a new instance of PingService.
14 15 16 17 18 19 |
# File 'lib/gorgon/ping_service.rb', line 14 def initialize @configuration = load_configuration_from_file("gorgon.json", merge: "gorgon_secret.json") @logger = OriginatorLogger.new @configuration[:originator_log_file] @protocol = OriginatorProtocol.new @logger @listeners = [] end |
Instance Method Details
#ping_listeners ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gorgon/ping_service.rb', line 21 def ping_listeners Signal.trap("INT") { disconnect } Signal.trap("TERM") { disconnect } EventMachine.run do @logger.log "Connecting..." @protocol.connect @configuration[:connection], :on_closed => proc {EM.stop} @logger.log "Pinging Listeners..." @protocol. :ping EM.add_timer(TIMEOUT) { disconnect } @protocol.receive_payloads do |payload| @logger.log "Received #{payload}" handle_reply(Yajl::Parser.new(:symbolize_keys => true).parse(payload)) end end end |