Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EugenMayer/55dc0aba37301b74f2d6c2dfa7d133fc to your computer and use it in GitHub Desktop.
Save EugenMayer/55dc0aba37301b74f2d6c2dfa7d133fc to your computer and use it in GitHub Desktop.
wait for socket
def wait_for_db(ip, port)
$stdout.sync = true
begin
puts 'Waiting for consul...'
Timeout::timeout(50) do
print '.'
begin
s = TCPSocket.new(ip, port)
s.close
return true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
# continue
end
end
rescue Timeout::Error
say_status 'error','DB never came up',:red
return false
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment