-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from icgood/check
Add health check client command
- Loading branch information
Showing
16 changed files
with
322 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pymapadmin/grpc/admin_grpc.py -diff | ||
pymapadmin/grpc/admin_pb2.py -diff | ||
pymapadmin/grpc/admin_pb2.pyi -diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
from __future__ import annotations | ||
|
||
from argparse import ArgumentParser | ||
from typing import Any, TextIO | ||
|
||
from grpclib.health.v1.health_grpc import HealthStub | ||
from grpclib.health.v1.health_pb2 import \ | ||
HealthCheckRequest, HealthCheckResponse | ||
|
||
from .base import ClientCommand | ||
from ..typing import RequestT, ResponseT, MethodProtocol | ||
|
||
__all__ = ['CheckCommand'] | ||
|
||
|
||
class HealthCommand(ClientCommand[HealthStub, RequestT, ResponseT]): | ||
|
||
@property | ||
def client(self) -> HealthStub: | ||
return HealthStub(self.channel) | ||
|
||
|
||
class CheckCommand(HealthCommand[HealthCheckRequest, | ||
HealthCheckResponse]): | ||
"""Check the health of the server.""" | ||
|
||
@classmethod | ||
def add_subparser(cls, name: str, subparsers: Any) \ | ||
-> ArgumentParser: # pragma: no cover | ||
return subparsers.add_parser( | ||
name, description=cls.__doc__, | ||
help='check the server health') | ||
|
||
@property | ||
def method(self) -> MethodProtocol[HealthCheckRequest, | ||
HealthCheckResponse]: | ||
return self.client.Check | ||
|
||
def build_request(self) -> HealthCheckRequest: | ||
return HealthCheckRequest() | ||
|
||
def _is_serving(self, response: HealthCheckResponse) -> bool: | ||
return response.status == HealthCheckResponse.ServingStatus.SERVING | ||
|
||
def handle_response(self, response: HealthCheckResponse, | ||
outfile: TextIO) -> int: | ||
print(response, file=outfile) | ||
return 0 if self._is_serving(response) else 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.