Method: Jets::RackServer#wait_for_socket

Defined in:
lib/jets/rack_server.rb

#wait_for_socketObject

blocks until rack server is up



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jets/rack_server.rb', line 54

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, Errno::EAFNOSUPPORT
    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