2
今日は時々ハングして問題を引き起こすgrpcサーバ/クライアントがあります。これは、Flaskアプリケーションから呼び出されています。このアプリケーションはバックグラウンドワーカープロセスにチェックインして、それが生きているか機能しているかを確認しています。 gRPCサーバに要求を行うには、私が持っている:どのように私は希望、このコードを使用してPythonのgRPCライブラリでタイムアウトを設定するには
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.company.project.worker";
option java_outer_classname = "ProjectWorker";
option objc_class_prefix = "PJW";
package projectworker;
service Worker {
rpc Health (Ping) returns (Pong) {}
}
// The request message containing PONG
message Ping {
string message = 1;
}
// The response message containing PONG
message Pong {
string message = 1;
}
:
channel = grpc.insecure_channel(address)
stub = WorkerStub(channel)
return stub
プロトがある:
try:
health = self.grpc_client.Health(self.health_ping)
if health.message == u'PONG':
return {
u'healthy': True,
u'message': {
u'healthy': True,
u'message': u'success'
},
u'status_code': 200
}
except Exception as e:
if str(e.code()) == u'StatusCode.UNAVAILABLE':
return {
u'healthy': False,
u'message': {
u'healthy': False,
u'message': (u'[503 Unavailable] connection to worker '
u'failed')},
u'status_code': 200}
elif str(e.code()) == u'StatusCode.INTERNAL':
return {
u'healthy': False,
u'message': {
u'healthy': False,
u'message': (u'[500 Internal] worker encountered '
u'an error while responding')},
u'status_code': 200}
return {
u'healthy': False,
u'message': {u'healthy': False, u'message': e.message},
u'status_code': 500
}
クライアントスタブですタイムアウトを追加して、失敗してハングアップするのではなく、常に応答できるようにします。
Ah、ok。その情報をありがとうございました!私はそれを逃したとは思わない – kkirsche