Skip to content

Commit 586ac62

Browse files
committed
use health check in python client
1 parent d324491 commit 586ac62

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

client/fossildb-client

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ from grpc_health.v1 import health_pb2_grpc
1313
def main():
1414

1515
commands = {
16-
'backup': lambda stub, healthStub:
16+
'backup': lambda stub:
1717
stub.Backup(proto.BackupRequest()),
18-
'restore': lambda stub, healthStub:
18+
'restore': lambda stub:
1919
stub.RestoreFromBackup(proto.RestoreFromBackupRequest()),
20-
'health': lambda stub, healthStub:
21-
healthStub.Check(health_pb2.HealthCheckRequest(service=''))
20+
'health': None
2221
}
2322

2423
parser = argparse.ArgumentParser()
@@ -47,11 +46,25 @@ def main():
4746
stub = proto_rpc.FossilDBStub(channel)
4847
healthStub = health_pb2_grpc.HealthStub(channel)
4948

50-
reply = commands[args.command](stub, healthStub)
49+
if args.command == 'health':
50+
try :
51+
reply = healthStub.Check(health_pb2.HealthCheckRequest(service=''))
52+
print(reply)
53+
UNKNOWN = 0;
54+
SERVING = 1;
55+
NOT_SERVING = 2;
56+
if reply.status != SERVING:
57+
raise Exception(reply.status)
58+
except Exception as e:
59+
print('Health check unsuccessful. FossilDB offline?')
60+
print(e)
61+
sys.exit(1)
5162

52-
print(reply)
53-
if not reply.success:
54-
sys.exit(1)
63+
else:
64+
reply = commands[args.command](stub)
65+
print(reply)
66+
if not reply.success:
67+
sys.exit(1)
5568

5669

5770
if __name__ == '__main__':

0 commit comments

Comments
 (0)