Module: OnContainer::Ops::ServiceConnectionChecks
- Defined in:
- lib/on_container/ops/service_connection_checks.rb
Instance Method Summary collapse
- #service_accepts_connections?(service_uri, seconds_to_wait = 30) ⇒ Boolean
- #wait_for_service_to_accept_connections(service_uri, seconds_to_wait = 30, exit_on_fail = true) ⇒ Object
Instance Method Details
#service_accepts_connections?(service_uri, seconds_to_wait = 30) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/on_container/ops/service_connection_checks.rb', line 10 def service_accepts_connections?(service_uri, seconds_to_wait = 30) uri = URI(service_uri) Timeout::timeout(seconds_to_wait) do TCPSocket.new(uri.host, uri.port).close rescue Errno::ECONNREFUSED retry end true rescue => e puts "Connection to #{uri.to_s} failed: '#{e.inspect}'" end |
#wait_for_service_to_accept_connections(service_uri, seconds_to_wait = 30, exit_on_fail = true) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/on_container/ops/service_connection_checks.rb', line 25 def wait_for_service_to_accept_connections(service_uri, seconds_to_wait = 30, exit_on_fail = true) wait_loop = Thread.new do loop do sleep(5) puts "Waiting for #{service_uri} to accept connections..." end end if service_accepts_connections?(service_uri, seconds_to_wait) return wait_loop.exit else exit 1 if exit_on_fail end end |