lib/envoy/client/channel.rb in envoy-proxy-0.1.4 vs lib/envoy/client/channel.rb in envoy-proxy-0.1.5

- old
+ new

@@ -10,10 +10,11 @@ @buffer = "" super() end def connection_completed + @tried_starting = nil send_data @buffer, true @buffer = nil end def send_data data, force = false @@ -33,26 +34,33 @@ end def unbind e if e == Errno::ECONNREFUSED if @tried_starting - @client.log "Service isn't running, but starting it didn't really work out." - @client.send_object :close, @id, 502 + if Time.now > @tried_starting + @client.options[:delay] + @client.log "Service isn't running, but starting it didn't really work out." + @client.send_object :close, @id, 502 + @tried_starting = false + else + EM.add_timer 0.1 do + reconnect + end + end elsif cmd = @client.options[:command] cmd = cmd % @client.options @client.log "Service doesn't seem to be running. Trying to start it now..." - @tried_starting = true + @tried_starting = Time.now + p @client.options[:dir] Dir.chdir File.expand_path(@client.options[:dir]) do fork do - #Process.daemon(true, false) ENV.delete("GEM_HOME") ENV.delete("GEM_PATH") ENV.delete("BUNDLE_BIN_PATH") ENV.delete("BUNDLE_GEMFILE") system cmd end end - EM.add_timer @client.options[:delay] do + EM.add_timer 0.1 do reconnect end end elsif e @client.log e.inspect