Class: Grpc::Health::Checker

Inherits:
V1::Health::Service show all
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

Methods included from GRPC::GenericService

included, underscore

Constructor Details

#initializeChecker

Initializes the statuses of participating services



29
30
31
32
# File 'src/ruby/pb/grpc/health/checker.rb', line 29

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.



47
48
49
# File 'src/ruby/pb/grpc/health/checker.rb', line 47

def add_status(service, status)
  @status_mutex.synchronize { @statuses["#{service}"] = status }
end

#check(req, _call) ⇒ Object

Implements the rpc IDL API method



35
36
37
38
39
40
41
42
43
44
# File 'src/ruby/pb/grpc/health/checker.rb', line 35

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_allObject

Clears alls the statuses.



57
58
59
# File 'src/ruby/pb/grpc/health/checker.rb', line 57

def clear_all
  @status_mutex.synchronize { @statuses = {} }
end

#clear_status(service) ⇒ Object

Clears the status for the given service.



52
53
54
# File 'src/ruby/pb/grpc/health/checker.rb', line 52

def clear_status(service)
  @status_mutex.synchronize { @statuses.delete("#{service}") }
end