14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/deploy_agent/agent.rb', line 14
def run
nio_selector = NIO::Selector.new
timers = Timers::Group.new
target = ENV['DEPLOY_AGENT_PROXY_IP'] || 'agent.deployhq.com'
server_connection = ServerConnection.new(self, target, nio_selector, !ENV['DEPLOY_AGENT_NOVERIFY'])
timers.every(60) { server_connection.keepalive }
loop do
wait_interval = timers.wait_interval
wait_interval = 0 if wait_interval < 0
nio_selector.select(wait_interval) do |monitor|
monitor.value.rx_data if monitor.readable?
monitor.value.tx_data if monitor.writeable?
end
timers.fire
@retries = 0
end
rescue OpenSSL::SSL::SSLError => e
@retries += 1
if @retries == 4
raise e
else
retry
end
rescue ServerConnection::ServerDisconnected
retry
rescue Interrupt, SignalException => e
logger.info("Stopping")
rescue Exception => e
logger.debug("#{e.class}: #{e.message}")
raise e
end
|