Skip to content

Commit edb3176

Browse files
authored
chore: add more clean sync step log (#789)
2 parents d0705fc + aa0b141 commit edb3176

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

backend/app/utils/server/sync_step.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,23 @@ async def wrapper(*args, **kwargs):
2424
value_json_str = value[len("data: ") :].strip()
2525
else:
2626
value_json_str = value
27-
json_data = json.loads(value_json_str)
28-
27+
28+
try:
29+
json_data = json.loads(value_json_str)
30+
except json.JSONDecodeError as e:
31+
logger.error(f"Failed to parse JSON in sync_step: {e}. Value: {value_json_str}")
32+
yield value
33+
continue
34+
35+
if "step" not in json_data or "data" not in json_data:
36+
logger.error(f"Missing 'step' or 'data' key in sync_step JSON. Keys: {list(json_data.keys())}")
37+
yield value
38+
continue
39+
2940
# Dynamic task_id extraction - prioritize runtime data over static args
3041
chat: Chat = args[0] if args and hasattr(args[0], 'task_id') else None
3142
task_id = None
32-
43+
3344
if chat is not None:
3445
task_lock = get_task_lock_if_exists(chat.project_id)
3546
if task_lock is not None:
@@ -38,7 +49,7 @@ async def wrapper(*args, **kwargs):
3849
else:
3950
logger.warning(f"Task lock not found for project_id {chat.project_id}, using chat.task_id")
4051
task_id = chat.task_id
41-
52+
4253
if task_id:
4354
asyncio.create_task(
4455
send_to_api(
@@ -62,4 +73,4 @@ async def send_to_api(url, data):
6273
res = await client.post(url, json=data)
6374
# logger.info(res)
6475
except Exception as e:
65-
logger.error(e)
76+
logger.error(f"Failed to sync step to {url}: {type(e).__name__}: {e}")

0 commit comments

Comments
 (0)