Class: Grpc::Health::Checker

Inherits:
V1alpha::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 =
V1alpha::HealthCheckResponse

Instance Method Summary collapse

Methods included from GRPC::GenericService

included, underscore

Constructor Details

#initializeChecker

Initializes the statuses of participating services


44
45
46
47
# File 'src/ruby/pb/grpc/health/checker.rb', line 44

def initialize
  @statuses = {}
  @status_mutex = Mutex.new  # guards access to @statuses
end

Instance Method Details

#add_status(host, service, status) ⇒ Object

Adds the health status for a given host and service.


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

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

#check(req, _call) ⇒ Object

Implements the rpc IDL API method


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

def check(req, _call)
  status = nil
  @status_mutex.synchronize do
    status = @statuses["#{req.host}/#{req.service}"]
  end
  fail GRPC::BadStatus, StatusCodes::NOT_FOUND if status.nil?
  HealthCheckResponse.new(status: status)
end

#clear_allObject

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(host, service) ⇒ Object

Clears the status for the given host or service.


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

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