Refactor SSE listener and improve logging for TELL updates
Build and Publish / build (push) Successful in 22s

Enhanced the SSE listener with better error handling and debug logs. Added checks for missing TELL URL and improved event data handling for "DewarContentUpdate". This ensures robustness and clarity in handling TELL updates.
This commit is contained in:
GotthardG
2025-06-24 13:07:02 +02:00
parent 7314a9dbf7
commit f14e652edd
+14 -10
View File
@@ -25,11 +25,20 @@ current_pucks = []
last_pucks_sent = []
def listen_to_sse():
print("[DEBUG] Entered listen_to_sse()")
if not tell_client.url:
print(f"[SSE][WARN] No TELL URL configured SSE listener not started. (tell_client.url={tell_client.url})")
return
sse_url = tell_client.url + "/events"
with requests.get(sse_url, stream=True) as response:
try:
response = requests.get(sse_url, stream=True)
client = sseclient.SSEClient(response)
for event in client:
on_sse_event(event)
for event in client.events():
if event.event == "DewarContentUpdate":
print(f"event: {event.event}, data: {event.data}")
on_sse_event(event)
except requests.exceptions.RequestException as exc:
print(f"[SSE][ERROR] Failed to connect to {sse_url}: {exc}")
def compare_and_report_change(old, new, key_func):
old_ids = set(key_func(p) for p in old)
@@ -71,15 +80,10 @@ def handle_tell_change_event():
print(f"[SSE][ERROR] {exc}")
def on_sse_event(event):
# event is an sseclient.Event object
print(f"Received SSE event: {event.event}")
print(f"[EVENT] SSE event: {event.event}")
print(f"[EVENT] Data: {event.data}")
if event.event == "DewarContentUpdate":
print("Dewar content changed, updating...")
# Option 1: Use event.data directly if it is complete puck info:
# puck_info = json.loads(event.data)
# do something with puck_info
# Option 2: Ask TELL again for fresh data
handle_tell_change_event()
def on_message(ws, message):