fix(site-import): FetchError 白话化映射(spec §6 行1)+ 预算语义注记
_pipeline 增 FetchError 分支(先于通用异常兜底):入口页不可达/超时—— 最高频真实失败路径——映射白话文案「网站打不开或响应太慢——检查 URL」 + phase=crawl(不可 retry);ImportTask docstring 的抓取失败归档口径 同步对齐。crawler 模块 docstring 注记 MAX_PAGES 预算语义(只计成功入编 页,链接农场广度消耗由总超时/并发/频控三层兜底)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from collections import defaultdict
|
||||
from app.platform.site_import import crawler, generator
|
||||
from app.platform.site_import.crawler import CrawlError, INSUFFICIENT_MESSAGE
|
||||
from app.platform.site_import.generator import GenerateError
|
||||
from app.platform.site_import.safe_fetch import FetchError
|
||||
|
||||
TASK_TTL = 30 * 60
|
||||
TOTAL_TIMEOUT = 7 * 60
|
||||
@@ -89,8 +90,8 @@ class ImportTask:
|
||||
"""一条导入任务:状态机 + 阶段产物 + 强引用的后台 aio task。
|
||||
|
||||
failed_phase:"generate" 可 retry=generate 复活(复用 crawl_result,
|
||||
不重抓);"crawl"(SPA/内容不足/抓取失败)与 None(超时落在抓取段/
|
||||
未知异常)不可复活——重开任务。
|
||||
不重抓);"crawl"(SPA/内容不足/FetchError 网站打不开)与 None(超时
|
||||
落在抓取段/未知异常)不可复活——重开任务。
|
||||
"""
|
||||
|
||||
def __init__(self, slug: str, task_id: str, url: str | None) -> None:
|
||||
@@ -201,6 +202,10 @@ async def _pipeline(task_obj: ImportTask) -> None:
|
||||
phase="generate" if task_obj.crawl_result is not None else None)
|
||||
except CrawlError as exc:
|
||||
task_obj.fail(str(exc), phase="crawl") # SPA/内容不足——不可 retry
|
||||
except FetchError:
|
||||
# spec §6 行1:入口页不可达/超时是最高频真实失败路径——白话文案,
|
||||
# 不漏进通用兜底裸抛英文内部信息
|
||||
task_obj.fail("网站打不开或响应太慢——检查 URL", phase="crawl")
|
||||
except GenerateError as exc:
|
||||
task_obj.fail(str(exc), phase="generate") # retry=generate 复活
|
||||
except Exception as exc: # 防御:未知异常不裸抛(任务表对象完整性优先)
|
||||
|
||||
Reference in New Issue
Block a user