Class: Async::GRPC::XDS::HealthChecker
- Inherits:
-
Object
- Object
- Async::GRPC::XDS::HealthChecker
- Defined in:
- lib/async/grpc/xds/health_checker.rb
Overview
Performs health checks on endpoints. Called by LoadBalancer’s loop. Runs within the caller’s reactor; does not spawn tasks or reactors. Only HTTP health checks are supported; gRPC health checks return :unknown.
Instance Method Summary collapse
-
#check(endpoint) ⇒ Object
Check health of endpoint.
-
#close ⇒ Object
Close health checker.
-
#initialize(health_checks) ⇒ HealthChecker
constructor
Initialize health checker.
-
#update_endpoints(endpoints) ⇒ Object
Update endpoints (cleans cache for removed endpoints).
Constructor Details
#initialize(health_checks) ⇒ HealthChecker
Initialize health checker
20 21 22 23 24 |
# File 'lib/async/grpc/xds/health_checker.rb', line 20 def initialize(health_checks) @health_checks = health_checks @endpoints = [] @cache = {} end |
Instance Method Details
#check(endpoint) ⇒ Object
Check health of endpoint. Runs in caller’s reactor.
37 38 39 40 41 42 43 44 45 |
# File 'lib/async/grpc/xds/health_checker.rb', line 37 def check(endpoint) if cached = @cache[endpoint] return cached[:status] if Time.now - cached[:time] < 5 end status = perform_check(endpoint) @cache[endpoint] = {status: status, time: Time.now} status end |
#close ⇒ Object
Close health checker
48 49 50 |
# File 'lib/async/grpc/xds/health_checker.rb', line 48 def close @cache.clear end |
#update_endpoints(endpoints) ⇒ Object
Update endpoints (cleans cache for removed endpoints)
28 29 30 31 32 |
# File 'lib/async/grpc/xds/health_checker.rb', line 28 def update_endpoints(endpoints) removed = @endpoints - endpoints removed.each{|endpoint| @cache.delete(endpoint)} @endpoints = endpoints end |