From fd83c2d1b2730b589725c8594cee90f64069fc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B8=85?= Date: Wed, 19 Aug 2026 17:37:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=A7=E7=BB=AD=E9=87=87=E9=9B=86?= =?UTF-8?q?=E5=AF=B9=E5=B8=B8=E8=A7=84=E4=BB=BB=E5=8A=A1=E6=97=A0=E6=95=88?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E9=80=80=E5=88=B0=E9=87=8D=E6=96=B0=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_service.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/task_service.py b/task_service.py index 69b4f98..de50d3d 100644 --- a/task_service.py +++ b/task_service.py @@ -522,6 +522,36 @@ def resume_task(public_id: str) -> dict[str, Any]: try: resumed = resume_collection(str(crawler_task_id)) except CrawlerError as exc: + err_msg = str(exc) + # 常规/轻度任务(overview 类型)的爬虫任务不支持断点恢复, + # 回退到从初始化阶段重新执行,避免前端返回 503 错误。 + if any(kw in err_msg for kw in ("不支持断点恢复", "sources 创建的任务")): + with connection() as conn: + row = conn.execute( + "SELECT id FROM research_tasks WHERE public_task_id=?", (public_id,) + ).fetchone() + task_pk = row["id"] if row else None + now = now_iso() + conn.execute( + """UPDATE research_tasks + SET status='waiting',execution_stage='queued',progress_percent=0, + cancel_requested_at=NULL,completed_at=NULL,error_code=NULL, + error_message=NULL,result_json=NULL,updated_at=?,version=version+1 + WHERE public_task_id=?""", + (now, public_id), + ) + if task_pk: + _event( + conn, task_pk, "retried", "queued", 0, "user", + payload={"resume_mode": "restart_initialization", "reason": "crawler_task_type_not_support_resume"}, + ) + threading.Thread( + target=_execute_task, + args=(public_id,), + daemon=True, + name=f"holy-crab-retry-{public_id}", + ).start() + return get_task(public_id) raise TaskError( "COLLECTOR_UNAVAILABLE", f"爬虫任务恢复失败:{exc}", 503 ) from exc