fix: robot pings to router
ref: N25B-256
This commit is contained in:
@@ -47,7 +47,7 @@ async def ping_stream(request: Request):
|
||||
sub_socket.setsockopt(zmq.SUBSCRIBE, b"ping")
|
||||
connected = False
|
||||
|
||||
ping_frequency = 1 # How many seconds between ping attempts
|
||||
ping_frequency = 2
|
||||
|
||||
# Even though its most likely the updates should alternate
|
||||
# So, True - False - True - False for connectivity.
|
||||
@@ -58,9 +58,10 @@ async def ping_stream(request: Request):
|
||||
topic, body = await asyncio.wait_for(
|
||||
sub_socket.recv_multipart(), timeout=ping_frequency
|
||||
)
|
||||
logger.debug("got ping change in ping_stream router")
|
||||
logger.debug(f"got ping change in ping_stream router: {body}")
|
||||
connected = json.loads(body)
|
||||
except TimeoutError:
|
||||
logger.debug("got timeout error in ping loop in ping router")
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
# Stop if client disconnected
|
||||
@@ -69,7 +70,7 @@ async def ping_stream(request: Request):
|
||||
break
|
||||
|
||||
logger.debug(f"Yielded new connection event in robot ping router: {str(connected)}")
|
||||
falseJson = json.dumps(connected)
|
||||
yield (f"data: {falseJson}\n\n")
|
||||
connectedJson = json.dumps(connected)
|
||||
yield (f"data: {connectedJson}\n\n")
|
||||
|
||||
return StreamingResponse(event_stream(), media_type="text/event-stream")
|
||||
|
||||
Reference in New Issue
Block a user