14 """Reference implementation for health checking in gRPC Python."""
24 if sys.version_info[0] >= 3
and sys.version_info[1] >= 6:
26 from .
import _async
as aio
29 SERVICE_NAME = _health_pb2.DESCRIPTOR.services_by_name[
'Health'].full_name
59 def add(self, response):
72 def send_response_callback(response):
78 return send_response_callback
82 """Servicer handling RPCs for service statuses."""
85 experimental_non_blocking=True,
86 experimental_thread_pool=None):
88 self.
_server_status = {
"": _health_pb2.HealthCheckResponse.SERVING}
90 self.
Watch.__func__.experimental_non_blocking = experimental_non_blocking
91 self.
Watch.__func__.experimental_thread_pool = experimental_thread_pool
99 send_response_callback)
100 send_response_callback(
None)
108 context.set_code(grpc.StatusCode.NOT_FOUND)
109 return _health_pb2.HealthCheckResponse()
111 return _health_pb2.HealthCheckResponse(status=status)
114 def Watch(self, request, context, send_response_callback=None):
115 blocking_watcher =
None
116 if send_response_callback
is None:
123 service = request.service
127 status = _health_pb2.HealthCheckResponse.SERVICE_UNKNOWN
128 send_response_callback(
129 _health_pb2.HealthCheckResponse(status=status))
133 context.add_callback(
135 return blocking_watcher
137 def set(self, service, status):
138 """Sets the status of a service.
141 service: string, the name of the service.
142 status: HealthCheckResponse.status enum value indicating the status of
153 send_response_callback(
154 _health_pb2.HealthCheckResponse(status=status))
157 """Permanently sets the status of all services to NOT_SERVING.
159 This should be invoked when the server is entering a graceful shutdown
160 period. After this method is invoked, future attempts to set the status
161 of a service will be ignored.
163 This is an EXPERIMENTAL API.
171 _health_pb2.HealthCheckResponse.NOT_SERVING)