Skip to content

Commit

Permalink
enhance ws_send by requeuing failed data for retry
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Dec 8, 2024
1 parent 7558108 commit 00ccd66
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions system/athena/athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,16 @@ def ws_recv(ws: WebSocket, end_event: threading.Event) -> None:

def ws_send(ws: WebSocket, end_event: threading.Event) -> None:
while not end_event.is_set():
data = None
queue_source = None
try:
try:
data = send_queue.get_nowait()
queue_source = send_queue
except queue.Empty:
data = low_priority_send_queue.get(timeout=1)
queue_source = low_priority_send_queue

for i in range(0, len(data), WS_FRAME_SIZE):
frame = data[i:i+WS_FRAME_SIZE]
last = i + WS_FRAME_SIZE >= len(data)
Expand All @@ -747,6 +752,11 @@ def ws_send(ws: WebSocket, end_event: threading.Event) -> None:
pass
except Exception:
cloudlog.exception("athenad.ws_send.exception")
if data is not None and queue_source is not None:
try:
queue_source.put_nowait(data)
except Exception:
cloudlog.exception("athenad.ws_send.requeue_failed")
end_event.set()


Expand Down

0 comments on commit 00ccd66

Please sign in to comment.