chore: 去掉 generic_steps 的默认步骤 + 重试失败带上真实原因

- tasks/generic/task.py:DEFAULT_PARAMS 只留 max_duration,**不再内置示例步骤**
  (步骤只能由前端编辑器产出;此前默认的"打开抖音→循环看视频"只有后端在用,
  编辑器新建任务本来就是空的,等于埋了个和界面不一致的隐性默认值)
- 空步骤不再静默空跑:worker 立即抛错「通用步骤任务没有可执行步骤…」,
  设备表「最近错误」能看到(此前会走完 0 步当成功)
- core/task_manager.py:重试耗尽的 last_error 现在带上最后一次的真实失败原因,
  不再只有"重试N次失败"(用户看不到为什么失败);max_attempts=1 显示"执行失败"
  而非费解的"重试1次失败";长度截断 200 字符
- 文档:TASK_DEV §2.10 说明无默认步骤 + 空步骤会报错;API.md 的 task_types 示例
  改 default_params={"max_duration":0},POST /api/jobs 补「steps 要一起传」提示

自测(全通过):default_params 无 steps;无步骤任务真跑一次 → 设备错误信息完整含原因;
有步骤任务(wait 1s)真跑一次 → status=done 无错误;临时任务验完已删,任务集合复原
This commit is contained in:
2026-09-10 21:50:18 +08:00
parent 98cdc39224
commit f4b5316436
4 changed files with 24 additions and 17 deletions
+9 -1
View File
@@ -757,7 +757,15 @@ class TaskManager:
time.sleep(delay)
_log.error(f"{serial} 任务 {job.name} 重试耗尽,放弃")
_update_status(serial, status="failed", last_error=f"{job.name} 重试{max_attempts}次失败")
# 带上最后一次的真实失败原因——只写"重试N次失败"会让用户看不到为什么失败
# (worker 出错时已把原因写进 _WORKERS[serial]["last_error"])
with _WORKERS_LOCK:
cause = (_WORKERS.get(serial, {}).get("last_error") or "").strip()
msg = (f"{job.name} 重试{max_attempts}次仍失败" if max_attempts > 1
else f"{job.name} 执行失败")
if cause and cause != msg:
msg += f":{cause}"
_update_status(serial, status="failed", last_error=msg[:200])
finally:
# 清除停止标志:整个重试循环结束(成功/失败/停止)后允许下次任务
with self._lock: