Class: ServiceWait::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/service_wait/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip, port, timeout = 20) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
# File 'lib/service_wait/runner.rb', line 6

def initialize(ip, port, timeout = 20)
  @ip = ip
  @port = port
  @timeout = timeout
end

Instance Method Details

#wait(&block) ⇒ Object



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

def wait(&block)
  Timeout::timeout(@timeout) do
    while !port_open?(@ip, @port)
      yield :failure if block_given?

      sleep 1
      yield :attempt if block_given?
    end

    yield :success if block_given?
  end

rescue Timeout::Error
  yield :timeout if block_given?
end