Module: Hudkins::HostLookup
- Defined in:
- lib/hudkins/restclient.rb
Overview
the idea behind this is that if the hudson server isn’t available, getaddrinfo has a really long timeout.. like over 20 seconds! This is really a DNS issue, but I still don’t want to wait that long and I couldn’t figure out how to set a better timeout.
Constant Summary collapse
- TIMEOUT =
defaults to 2
2
Class Method Summary collapse
-
.available?(uri, timeout = nil) ⇒ Boolean
timeout Socket.getaddrinfo after TIMEOUT seconds.
Class Method Details
.available?(uri, timeout = nil) ⇒ Boolean
timeout Socket.getaddrinfo after TIMEOUT seconds
returns true/false
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hudkins/restclient.rb', line 114 def self.available? uri, timeout = nil timeout ||= TIMEOUT pid = fork do Socket.getaddrinfo( uri.host, uri.scheme ) end begin Timeout::timeout(timeout) do Process.wait(pid) end true rescue Timeout::Error Process.kill(9, pid) false end end |