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

#add_statuses(service_statuses = {}) ⇒ Object

Adds health status for each service given within hash



59
60
61
62
63
# File 'src/ruby/pb/grpc/health/checker.rb', line 59

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



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.



71
72
73
# File 'src/ruby/pb/grpc/health/checker.rb', line 71

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

#clear_status(service) ⇒ Object

Clears the status for the given service.



66
67
68
# File 'src/ruby/pb/grpc/health/checker.rb', line 66

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



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

def set_status_for_services(status, *services)
  @status_mutex.synchronize do
    services.each { |service| @statuses["#{service}"] = status }
  end
end