Class: Nonnative::GRPCHealth
- Inherits:
-
Object
- Object
- Nonnative::GRPCHealth
- Defined in:
- lib/nonnative/grpc_health.rb
Overview
Client helper for the standard gRPC health checking protocol.
Constant Summary collapse
- NETWORK_ERRORS =
[ GRPC::BadStatus, GRPC::Core::CallError ].freeze
Instance Method Summary collapse
-
#check(deadline: Time.now + timeout) ⇒ Grpc::Health::V1::HealthCheckResponse
Calls the gRPC health check endpoint.
-
#endpoint ⇒ String
Returns the checked gRPC health endpoint for lifecycle diagnostics.
-
#initialize(host:, port:, service:, timeout: 1) ⇒ GRPCHealth
constructor
A new instance of GRPCHealth.
-
#serving?(deadline: Time.now + timeout) ⇒ Boolean
Returns true when the gRPC health endpoint reports SERVING.
Constructor Details
#initialize(host:, port:, service:, timeout: 1) ⇒ GRPCHealth
Returns a new instance of GRPCHealth.
15 16 17 18 19 20 |
# File 'lib/nonnative/grpc_health.rb', line 15 def initialize(host:, port:, service:, timeout: 1) @host = host @port = port @service = service.to_s @timeout = timeout end |
Instance Method Details
#check(deadline: Time.now + timeout) ⇒ Grpc::Health::V1::HealthCheckResponse
Calls the gRPC health check endpoint.
26 27 28 |
# File 'lib/nonnative/grpc_health.rb', line 26 def check(deadline: Time.now + timeout) stub.check(request, deadline: deadline) end |
#endpoint ⇒ String
Returns the checked gRPC health endpoint for lifecycle diagnostics.
43 44 45 |
# File 'lib/nonnative/grpc_health.rb', line 43 def endpoint service.empty? ? "grpc://#{host}:#{port}" : "grpc://#{host}:#{port}/#{service}" end |
#serving?(deadline: Time.now + timeout) ⇒ Boolean
Returns true when the gRPC health endpoint reports SERVING.
34 35 36 37 38 |
# File 'lib/nonnative/grpc_health.rb', line 34 def serving?(deadline: Time.now + timeout) check(deadline: deadline).status == :SERVING rescue *NETWORK_ERRORS false end |