Class: Nonnative::HTTPProbe

Inherits:
HTTPClient show all
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

Constructor Details

#initialize(process) ⇒ HTTPProbe

Returns a new instance of HTTPProbe.

Parameters:



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

#endpointString

Returns the HTTP readiness endpoint for lifecycle diagnostics.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


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