Module: ShuntCache::Checker
- Defined in:
- lib/shunt_cache/checker.rb
Class Method Summary collapse
Class Method Details
.request(uri, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shunt_cache/checker.rb', line 26 def request(uri, = {}) timeout = .fetch(:timeout, 10) response = nil Net::HTTP.start(uri.host, uri.port) do |http| http.read_timeout = timeout request = Net::HTTP::Get.new(uri.path) request['Host'] = [:host] if [:host] response = http.request(request) end response end |
.wait_for_http(url, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/shunt_cache/checker.rb', line 7 def wait_for_http(url, = {}) retries = .fetch(:retry, 10) wait_time = .fetch(:wait_time, 6) uri = URI(url) retries.times do begin response = request(uri, ) code = response.code.to_i return true if 200 <= code && 399 >= code rescue Errno::ECONNREFUSED, Timeout::Error => e end sleep(wait_time) end false end |