Class: Gorgon::GemService

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/gorgon/gem_service.rb

Constant Summary collapse

TIMEOUT =
3

Instance Method Summary collapse

Methods included from Configuration

#load_configuration_from_file

Constructor Details

#initializeGemService

Returns a new instance of GemService.



11
12
13
14
15
16
17
18
# File 'lib/gorgon/gem_service.rb', line 11

def initialize
  @configuration = load_configuration_from_file("gorgon.json", merge: "gorgon_secret.json")
  @logger = OriginatorLogger.new @configuration[:originator_log_file]
  @protocol = OriginatorProtocol.new @logger
  @hosts_running = []
  @started_running = 0
  @finished_running = 0
end

Instance Method Details

#run(command) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gorgon/gem_service.rb', line 20

def run command
  EM.run do
    @logger.log "Connecting..."
    @protocol.connect @configuration[:connection],  :on_closed => proc {EM.stop}

    @logger.log "Sending gem command #{command}..."
    @protocol.send_message_to_listeners :gem_command, :gem_command => command

    @protocol.receive_payloads do |payload|
      @logger.log "Received #{payload}"

      handle_reply(Yajl::Parser.new(:symbolize_keys => true).parse(payload))
    end

    EM.add_periodic_timer(TIMEOUT) { disconnect_if_none_running }
  end
end