Method: Jets::RackServer#wait_for_socket
- Defined in:
- lib/jets/rack_server.rb
#wait_for_socket ⇒ Object
blocks until rack server is up
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jets/rack_server.rb', line 48 def wait_for_socket return unless Jets.rack? retries = 0 max_retries = 30 # 15 seconds at a delay of 0.5s delay = 0.5 if ENV['C9_USER'] # overrides for local testing max_retries = 3 delay = 3 end begin server = TCPSocket.new('localhost', 9292) server.close rescue Errno::ECONNREFUSED puts "Unable to connect to localhost:9292. Delay for #{delay} and will try to connect again." if ENV['JETS_DEBUG'] sleep(delay) retries += 1 if retries < max_retries retry else puts "Giving up on trying to connect to localhost:9292" return false end end puts "Connected to localhost:9292 successfully" true end |