46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/opstat-master/master.rb', line 46
def self.main_loop
mq_config = Opstat::Config.instance.get_mq_config
Opstat::Parsers::Master.instance.load_parsers
oplogger.info 'START'
EventMachine::run do
AMQP.start(mq_config) do |connection|
oplogger.info "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
channel = AMQP::Channel.new(connection,:auto_recovery => true)
ampqqueue = channel.queue(mq_config['queue_name'],:auto_delete => false, :durable => true)
connection.on_tcp_connection_loss do |conn, settings|
oplogger.error "[network failure] Trying to reconnect..."
conn.reconnect(false, 2)
end
ampqqueue.subscribe(:ack => true) do |metadata,payload|
TaskServer::save(JSON.parse(payload))
metadata.ack
end
end
end
end
|