fix: Fix up merging request changes and make sure that there is no racing condition errors, and UI always gets correct information.
ref: N25B-256
This commit is contained in:
@@ -21,7 +21,6 @@ async def receive_command(command: SpeechCommand, request: Request):
|
||||
SpeechCommand.model_validate(command)
|
||||
topic = b"command"
|
||||
|
||||
# TODO: Check with Kasper
|
||||
pub_socket: Socket = request.app.state.endpoints_pub_socket
|
||||
await pub_socket.send_multipart([topic, command.model_dump_json().encode()])
|
||||
|
||||
@@ -48,8 +47,8 @@ async def ping_stream(request: Request):
|
||||
ping_frequency = 2
|
||||
|
||||
# Even though its most likely the updates should alternate
|
||||
# So, True - False - True - False for connectivity.
|
||||
# Let's still check:)
|
||||
# (So, True - False - True - False for connectivity),
|
||||
# let's still check.
|
||||
while True:
|
||||
try:
|
||||
topic, body = await asyncio.wait_for(
|
||||
@@ -58,11 +57,11 @@ async def ping_stream(request: Request):
|
||||
connected = json.loads(body)
|
||||
except TimeoutError:
|
||||
logger.debug("got timeout error in ping loop in ping router")
|
||||
await asyncio.sleep(0.1)
|
||||
connected = False
|
||||
|
||||
# Stop if client disconnected
|
||||
if await request.is_disconnected():
|
||||
print("Client disconnected from SSE")
|
||||
logger.info("Client disconnected from SSE")
|
||||
break
|
||||
|
||||
logger.debug(f"Yielded new connection event in robot ping router: {str(connected)}")
|
||||
|
||||
Reference in New Issue
Block a user