feat: include failed step in task errors
This commit is contained in:
@@ -23,6 +23,37 @@ VALID_BATCH_FIELDS = {
|
||||
"deleted_at",
|
||||
"deleted_reason",
|
||||
}
|
||||
FAILURE_STEP_LABELS = {
|
||||
"preflight": "预检",
|
||||
"check_chrome": "检查Chrome",
|
||||
"login_check": "检测登录",
|
||||
"open_product": "打开商品页",
|
||||
"wait_ready": "页面就绪",
|
||||
"read_title": "读标题",
|
||||
"read_cover": "读封面",
|
||||
"download_cover": "下载封面",
|
||||
"db_write": "写库",
|
||||
"excel_write_back": "回写Excel",
|
||||
"write_excel": "回写Excel",
|
||||
"load_text_model": "加载文本模型",
|
||||
"title_submit": "提交标题任务",
|
||||
"title_build_request": "构建标题请求",
|
||||
"title_request": "请求生成标题",
|
||||
"title_parse_response": "解析标题响应",
|
||||
"load_image_model": "加载图片模型",
|
||||
"cover_validate_input": "校验旧封面",
|
||||
"cover_prompt_render": "渲染封面提示词",
|
||||
"cover_submit": "提交封面任务",
|
||||
"cover_build_request": "构建封面请求",
|
||||
"cover_request": "请求生成封面",
|
||||
"cover_download": "下载新封面",
|
||||
"cover_save": "保存新封面",
|
||||
"cover_parse_response": "解析封面响应",
|
||||
"apply_task": "更新商品",
|
||||
"change_title": "修改标题",
|
||||
"replace_cover": "更新封面",
|
||||
"click_update": "点击更新",
|
||||
}
|
||||
VALID_ACCOUNT_FIELDS = {
|
||||
"account_name",
|
||||
"alias",
|
||||
@@ -607,8 +638,28 @@ def mark_running(task_id, phase, path=None, conn=None) -> None:
|
||||
)
|
||||
|
||||
|
||||
def mark_failed(task_id, phase, error, path=None, conn=None) -> None:
|
||||
def failure_step_label(step):
|
||||
value = str(step or "").strip()
|
||||
return FAILURE_STEP_LABELS.get(value, value)
|
||||
|
||||
|
||||
def format_failure_error(error, step=None):
|
||||
message = str(error or "")
|
||||
label = failure_step_label(step)
|
||||
if not label:
|
||||
return message
|
||||
prefix = f"{label}失败:"
|
||||
if message.startswith(prefix):
|
||||
return message
|
||||
for known_label in FAILURE_STEP_LABELS.values():
|
||||
if message.startswith(f"{known_label}失败:") or message.startswith(f"{known_label}失败:"):
|
||||
return message
|
||||
return prefix + message
|
||||
|
||||
|
||||
def mark_failed(task_id, phase, error, path=None, conn=None, step=None) -> None:
|
||||
attempt_field = _attempt_field(phase)
|
||||
formatted_error = format_failure_error(error, step)
|
||||
with _connection(conn, path) as database:
|
||||
with database:
|
||||
database.execute(
|
||||
@@ -620,7 +671,7 @@ def mark_failed(task_id, phase, error, path=None, conn=None) -> None:
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(str(error), _now(), int(task_id)),
|
||||
(formatted_error, _now(), int(task_id)),
|
||||
)
|
||||
|
||||
|
||||
@@ -708,7 +759,7 @@ def update_generated_title(task_id, new_title, path=None, conn=None) -> None:
|
||||
(title, now, int(task_id)),
|
||||
)
|
||||
|
||||
def set_applied(task_id, committed, error=None, path=None, conn=None) -> None:
|
||||
def set_applied(task_id, committed, error=None, path=None, conn=None, step=None) -> None:
|
||||
now = _now()
|
||||
success = bool(committed) and error is None
|
||||
with _connection(conn, path) as database:
|
||||
@@ -729,6 +780,7 @@ def set_applied(task_id, committed, error=None, path=None, conn=None) -> None:
|
||||
(now, now, int(task_id)),
|
||||
)
|
||||
else:
|
||||
formatted_error = format_failure_error(error or "未提交更新", step)
|
||||
database.execute(
|
||||
"""
|
||||
UPDATE tasks
|
||||
@@ -739,7 +791,7 @@ def set_applied(task_id, committed, error=None, path=None, conn=None) -> None:
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(str(error or "未提交更新"), now, int(task_id)),
|
||||
(formatted_error, now, int(task_id)),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user