Refactor SSE connection handling in tellupdater for simplicity and robustness

This commit is contained in:
GotthardG
2026-03-10 10:15:23 +01:00
parent 989624b319
commit 661db1315d
+5 -11
View File
@@ -40,23 +40,17 @@ def listen_to_sse():
return
sse_url = tell_client.url + "/events"
try:
response = requests.get(sse_url, stream=True)
client = sseclient.SSEClient(response)
#response = requests.get(sse_url, stream=True)
client = sseclient.SSEClient(sse_url)
# Immediately fetch current detected pucks once on connect so the system starts with
# up-to-date state (instead of waiting for the first DewarContentUpdate event).
try:
print("[SSE][listen_to_sse] Initial detected pucks fetch on connect")
handle_tell_change_event()
except Exception as exc:
print(f"[SSE][listen_to_sse][WARN] Initial fetch failed: {exc}")
print("[SSE][listen_to_sse] Initial detected pucks fetch on connect")
handle_tell_change_event()
for event in client.events():
print(f"event = {event.event} with data: {event.data}")
if event.event == "DewarContentUpdate":
print(f"[SSE][listen_to_sse] event: {event.event}, data: {event.data}")
on_sse_event(event)
except requests.exceptions.RequestException as exc:
except Exception as exc:
print(f"[SSE][listen_to_sse][ERROR] Failed to connect to {sse_url}: {exc}")
def compare_and_report_change(old, new, key_func):