Fixes related to failed grpc network connection
Add timeouts to all gRPC remote calls and bump yagrc package requirement to a version that does same for the reflection service, as well as fixing a state issue around failed lazy import resolution. This should address the script hang symptom on issue #36.
This commit is contained in:
parent
833f82f575
commit
c35588d01f
3 changed files with 10 additions and 5 deletions
|
@ -11,7 +11,7 @@ from spacex.api.device import dish_pb2
|
|||
# call channel.close() when you're done with the gRPC connection.
|
||||
with grpc.insecure_channel("192.168.100.1:9200") as channel:
|
||||
stub = device_pb2_grpc.DeviceStub(channel)
|
||||
response = stub.Handle(device_pb2.Request(get_status={}))
|
||||
response = stub.Handle(device_pb2.Request(get_status={}), timeout=10)
|
||||
|
||||
# Dump everything
|
||||
print(response)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
grpcio>=1.12.0
|
||||
grpcio-tools>=1.20.0
|
||||
protobuf>=3.6.0
|
||||
yagrc>=1.1.0
|
||||
yagrc>=1.1.1
|
||||
paho-mqtt>=1.5.1
|
||||
influxdb>=5.3.1
|
||||
pypng>=0.0.20
|
||||
|
|
|
@ -351,6 +351,10 @@ from spacex.api.device import device_pb2
|
|||
from spacex.api.device import device_pb2_grpc
|
||||
from spacex.api.device import dish_pb2
|
||||
|
||||
# Max wait time for gRPC request completion, in seconds. This is just to
|
||||
# prevent hang if the connection goes dead without closing.
|
||||
REQUEST_TIMEOUT = 10
|
||||
|
||||
HISTORY_FIELDS = ("pop_ping_drop_rate", "pop_ping_latency_ms", "downlink_throughput_bps",
|
||||
"uplink_throughput_bps")
|
||||
|
||||
|
@ -546,7 +550,7 @@ def get_status(context=None):
|
|||
if imports_pending:
|
||||
resolve_imports(channel)
|
||||
stub = device_pb2_grpc.DeviceStub(channel)
|
||||
response = stub.Handle(device_pb2.Request(get_status={}))
|
||||
response = stub.Handle(device_pb2.Request(get_status={}), timeout=REQUEST_TIMEOUT)
|
||||
return response.dish_get_status
|
||||
|
||||
return call_with_channel(grpc_call, context=context)
|
||||
|
@ -816,7 +820,7 @@ def get_history(context=None):
|
|||
if imports_pending:
|
||||
resolve_imports(channel)
|
||||
stub = device_pb2_grpc.DeviceStub(channel)
|
||||
response = stub.Handle(device_pb2.Request(get_history={}))
|
||||
response = stub.Handle(device_pb2.Request(get_history={}), timeout=REQUEST_TIMEOUT)
|
||||
return response.dish_get_history
|
||||
|
||||
return call_with_channel(grpc_call, context=context)
|
||||
|
@ -1209,7 +1213,8 @@ def get_obstruction_map(context=None):
|
|||
if imports_pending:
|
||||
resolve_imports(channel)
|
||||
stub = device_pb2_grpc.DeviceStub(channel)
|
||||
response = stub.Handle(device_pb2.Request(dish_get_obstruction_map={}))
|
||||
response = stub.Handle(device_pb2.Request(dish_get_obstruction_map={}),
|
||||
timeout=REQUEST_TIMEOUT)
|
||||
return response.dish_get_obstruction_map
|
||||
|
||||
return call_with_channel(grpc_call, context=context)
|
||||
|
|
Loading…
Reference in a new issue