fix: 浏览内容/附件进度实时更新

This commit is contained in:
2025-12-16 19:51:27 +08:00
parent 2abb9ab494
commit 71cc518fe8
2 changed files with 89 additions and 17 deletions

View File

@@ -590,12 +590,46 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
safe_update_task_status(account_id, {"detail_status": "正在浏览"})
log_to_client(f"开始浏览 '{browse_type}' 内容...", user_id, account_id)
account.total_items = 0
account.total_attachments = 0
safe_update_task_status(account_id, {"progress": {"items": 0, "attachments": 0}})
def should_stop():
return account.should_stop
last_progress_ts = 0.0
def on_browse_progress(progress: dict):
nonlocal last_progress_ts
try:
now_ts = time_module.time()
if now_ts - last_progress_ts < 0.5:
return
last_progress_ts = now_ts
total_items = int(progress.get("total_items") or 0)
browsed_items = int(progress.get("browsed_items") or 0)
total_attachments = int(progress.get("total_attachments") or 0)
viewed_attachments = int(progress.get("viewed_attachments") or 0)
if total_items > 0:
account.total_items = total_items
else:
account.total_items = max(int(getattr(account, "total_items", 0) or 0), browsed_items)
account.total_attachments = max(total_attachments, viewed_attachments)
safe_update_task_status(
account_id, {"progress": {"items": browsed_items, "attachments": viewed_attachments}}
)
except Exception:
pass
checkpoint_mgr.update_stage(task_id, TaskStage.BROWSING, progress_percent=50)
result = api_browser.browse_content(browse_type=browse_type, should_stop_callback=should_stop)
result = api_browser.browse_content(
browse_type=browse_type,
should_stop_callback=should_stop,
progress_callback=on_browse_progress,
)
else:
error_message = "登录失败"
log_to_client(f"{error_message}", user_id, account_id)