Class: Nonnative::HTTPProbe
- Inherits:
-
HTTPClient
- Object
- HTTPClient
- Nonnative::HTTPProbe
- Defined in:
- lib/nonnative/http_probe.rb
Overview
Probes a managed process HTTP readiness endpoint.
Constant Summary collapse
- NETWORK_ERRORS =
[ Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, SocketError, RestClient::Exceptions::Timeout, RestClient::ServerBrokeConnection ].freeze
Instance Method Summary collapse
-
#endpoint ⇒ String
Returns the HTTP readiness endpoint for lifecycle diagnostics.
-
#initialize(process) ⇒ HTTPProbe
constructor
A new instance of HTTPProbe.
-
#ready? ⇒ Boolean
Returns whether the configured HTTP endpoint returns a 2xx response before timeout.
Constructor Details
#initialize(process) ⇒ HTTPProbe
Returns a new instance of HTTPProbe.
16 17 18 19 20 21 22 |
# File 'lib/nonnative/http_probe.rb', line 16 def initialize(process) @readiness = process.readiness @base_url = "http://#{process.host}:#{readiness.port}" @timeout = Nonnative::Timeout.new(process.timeout) super(base_url) end |
Instance Method Details
#endpoint ⇒ String
Returns the HTTP readiness endpoint for lifecycle diagnostics.
44 45 46 |
# File 'lib/nonnative/http_probe.rb', line 44 def endpoint "#{base_url}#{path}" end |
#ready? ⇒ Boolean
Returns whether the configured HTTP endpoint returns a 2xx response before timeout.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nonnative/http_probe.rb', line 27 def ready? Nonnative.logger.info "checking if readiness '#{endpoint}' is ready" timeout.perform do response = get(readiness.path) raise Nonnative::Error unless ready_response?(response) true rescue Nonnative::Error, *NETWORK_ERRORS sleep_interval retry end end |