Class: Nonnative::GRPCProbe

Inherits:
Object
  • Object
show all
Defined in:
lib/nonnative/grpc_probe.rb

Overview

Probes a managed process gRPC health endpoint.

Instance Method Summary collapse

Constructor Details

#initialize(process, readiness) ⇒ GRPCProbe

Returns a new instance of GRPCProbe.

Parameters:



8
9
10
11
12
13
14
15
16
# File 'lib/nonnative/grpc_probe.rb', line 8

def initialize(process, readiness)
  @health = Nonnative::GRPCHealth.new(
    host: process.host,
    port: readiness.port,
    service: readiness.service,
    timeout: process.timeout
  )
  @timeout = Nonnative::Timeout.new(process.timeout)
end

Instance Method Details

#endpointString

Returns the gRPC health endpoint for lifecycle diagnostics.

Returns:

  • (String)


37
38
39
# File 'lib/nonnative/grpc_probe.rb', line 37

def endpoint
  health.endpoint
end

#ready?Boolean

Returns whether the configured gRPC health endpoint reports SERVING before timeout.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nonnative/grpc_probe.rb', line 21

def ready?
  Nonnative.logger.info "checking if readiness '#{endpoint}' is ready"

  timeout.perform do
    raise Nonnative::Error unless health.serving?

    true
  rescue Nonnative::Error
    sleep_interval
    retry
  end
end