69068e2e39
部署对齐三项后端能力:启动/周期收尾僵尸批量任务、30 天推送日志 purge、已安装且版本不低于主站时跳过批量安装 Agent。 Co-authored-by: Cursor <cursoragent@cursor.com>
1.2 KiB
1.2 KiB
2026-06-08 — server_batch 僵尸回收与 stuck 扫描
背景
部署/API 重启后,批量任务 asyncio 协程丢失,Redis/MySQL 仍保持 running(例:任务 #20)。脚本执行已有 detect_stuck_executions,批量任务缺失对等机制。
方案
- 启动回收(#1):primary worker
lifespan在 Redis 就绪后调用recover_orphaned_batch_jobs(),扫描 Redisserver_batch:*与 MySQLstatus=running,将未完成服务器标为失败(「服务重启导致任务中断」),finalize并落库/审计。 - 周期 stuck(#2):
server_batch_reconcile_loop每 60s 调用detect_stuck_batch_jobs(),updated_at超过 1h 的running任务自动收尾(「执行超时无响应」)。
涉及文件
server/infrastructure/redis/server_batch_store.pyserver/infrastructure/database/server_batch_job_repo.pyserver/application/services/server_batch_service.pyserver/background/server_batch_reconcile.pyserver/main.py
测试
pytest tests/test_server_batch_reconcile.py -q
bash scripts/local_verify.sh
回滚
移除 main.py 启动/后台任务接线;已 finalize 的任务不可自动恢复。