Class: Ringleader::WaitForPort

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger
Defined in:
lib/ringleader/wait_for_port.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, app) ⇒ WaitForPort

Returns a new instance of WaitForPort.



6
7
8
9
# File 'lib/ringleader/wait_for_port.rb', line 6

def initialize(host, port, app)
  @host, @port, @app = host, port, app
  async.wait
end

Instance Method Details

#waitObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ringleader/wait_for_port.rb', line 11

def wait
  begin
    TCPSocket.new @host, @port
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
    debug "#{@host}:#{@port} not open yet"
    sleep 0.5
    retry
  rescue IOError, SystemCallError => e
    error "unexpected error while waiting for port: #{e}"
    sleep 0.5
    retry
  end
  debug "#{@host}:#{@port} open"
  @app.async.port_opened
  terminate
end