fix: robot pings to router

ref: N25B-256
This commit is contained in:
Björn Otgaar
2025-11-05 16:59:36 +01:00
parent 8638523980
commit ca8b57fec5

View File

@@ -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")