fix: 继续采集对常规任务无效,回退到重新初始化执行
This commit is contained in:
@@ -522,6 +522,36 @@ def resume_task(public_id: str) -> dict[str, Any]:
|
|||||||
try:
|
try:
|
||||||
resumed = resume_collection(str(crawler_task_id))
|
resumed = resume_collection(str(crawler_task_id))
|
||||||
except CrawlerError as exc:
|
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(
|
raise TaskError(
|
||||||
"COLLECTOR_UNAVAILABLE", f"爬虫任务恢复失败:{exc}", 503
|
"COLLECTOR_UNAVAILABLE", f"爬虫任务恢复失败:{exc}", 503
|
||||||
) from exc
|
) from exc
|
||||||
|
|||||||
Reference in New Issue
Block a user