Class: Grpc::Health::Checker
- Inherits:
-
V1::Health::Service
- Object
- V1::Health::Service
- Grpc::Health::Checker
- Defined in:
- src/ruby/pb/grpc/health/checker.rb
Overview
Checker is implementation of the schema-specified health checking service.
Constant Summary collapse
- StatusCodes =
GRPC::Core::StatusCodes
- HealthCheckResponse =
V1::HealthCheckResponse
Instance Method Summary collapse
-
#add_status(service, status) ⇒ Object
Adds the health status for a given service.
-
#add_statuses(service_statuses = {}) ⇒ Object
Adds health status for each service given within hash.
-
#check(req, _call) ⇒ Object
Implements the rpc IDL API method.
-
#clear_all ⇒ Object
Clears alls the statuses.
-
#clear_status(service) ⇒ Object
Clears the status for the given service.
-
#initialize ⇒ Checker
constructor
Initializes the statuses of participating services.
-
#set_status_for_services(status, *services) ⇒ Object
Adds given health status for all given services.
Methods included from GRPC::GenericService
Constructor Details
#initialize ⇒ Checker
Initializes the statuses of participating services
28 29 30 31 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 28 def initialize @statuses = {} @status_mutex = Mutex.new # guards access to @statuses end |
Instance Method Details
#add_status(service, status) ⇒ Object
Adds the health status for a given service.
46 47 48 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 46 def add_status(service, status) @status_mutex.synchronize { @statuses["#{service}"] = status } end |
#add_statuses(service_statuses = {}) ⇒ Object
Adds health status for each service given within hash
58 59 60 61 62 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 58 def add_statuses(service_statuses = {}) @status_mutex.synchronize do service_statuses.each_pair { |service, status| @statuses["#{service}"] = status } end end |
#check(req, _call) ⇒ Object
Implements the rpc IDL API method
34 35 36 37 38 39 40 41 42 43 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 34 def check(req, _call) status = nil @status_mutex.synchronize do status = @statuses["#{req.service}"] end if status.nil? fail GRPC::BadStatus.new_status_exception(StatusCodes::NOT_FOUND) end HealthCheckResponse.new(status: status) end |
#clear_all ⇒ Object
Clears alls the statuses.
70 71 72 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 70 def clear_all @status_mutex.synchronize { @statuses = {} } end |
#clear_status(service) ⇒ Object
Clears the status for the given service.
65 66 67 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 65 def clear_status(service) @status_mutex.synchronize { @statuses.delete("#{service}") } end |
#set_status_for_services(status, *services) ⇒ Object
Adds given health status for all given services
51 52 53 54 55 |
# File 'src/ruby/pb/grpc/health/checker.rb', line 51 def set_status_for_services(status, *services) @status_mutex.synchronize do services.each { |service| @statuses["#{service}"] = status } end end |