fix: 进度实时推送与排队推送节流

This commit is contained in:
2025-12-16 20:36:32 +08:00
parent 71cc518fe8
commit 0144812f30
2 changed files with 62 additions and 2 deletions

View File

@@ -603,7 +603,7 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
nonlocal last_progress_ts
try:
now_ts = time_module.time()
if now_ts - last_progress_ts < 0.5:
if now_ts - last_progress_ts < 1.0:
return
last_progress_ts = now_ts
@@ -621,6 +621,22 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
safe_update_task_status(
account_id, {"progress": {"items": browsed_items, "attachments": viewed_attachments}}
)
account_data = account.to_dict()
_emit(
"task_progress",
{
"account_id": account_id,
"stage": account_data.get("detail_status", ""),
"total_items": int(account.total_items or 0),
"browsed_items": browsed_items,
"total_attachments": int(account.total_attachments or 0),
"viewed_attachments": viewed_attachments,
"start_time": account_data.get("start_time", 0),
"elapsed_seconds": account_data.get("elapsed_seconds", 0),
"elapsed_display": account_data.get("elapsed_display", ""),
},
room=f"user_{user_id}",
)
except Exception:
pass