Created
July 28, 2016 20:24
-
-
Save EugenMayer/55dc0aba37301b74f2d6c2dfa7d133fc to your computer and use it in GitHub Desktop.
wait for socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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