aa65f10c52
Audit docs:
- docs/reports/audit-phase-2{a-j}-line-walk.md: per-file line walk findings
- docs/reports/audit-phase-2-findings-matrix.md: 63 findings (52 fixed, 3 partial, 7 accepted)
- docs/reports/2026-05-23-full-audit-report.md: full audit consolidation
- docs/reports/audit-full-vs-phase2-reconciliation.md: cross-reference
- docs/reports/audit-phase-2-walk-closure.md: closure sign-off
Project docs:
- docs/project/phase-2-audit-remediation.md: SSOT for all fixes
- docs/project/alert-push-policy.md: dashboard alert design decisions
- docs/project/production-verification-checklist.md: first-deploy checklist
- docs/project/script-execution.md: script platform design
- docs/project/wsl-integration-test.md: WSL code-only verification guide
- docs/project/line-walk-audit-standard.md: audit methodology
- docs/project/mysql-mcp-setup.md: MCP config guide
Changelogs: 18 entries (2026-05-22 to 2026-05-23)
Project memory: CLAUDE.md, AGENTS.md updated to reflect current state
Deploy: nginx_https.conf template updated
Co-authored-by: Cursor <cursoragent@cursor.com>
2.5 KiB
2.5 KiB
Changelog — 长任务回调与 Redis 执行态
日期: 2026-05-22
类型: 功能
上级索引: 2026-05-22-script-execution-platform.md
SSOT: docs/project/script-execution.md
变更摘要
- 长任务:
nohup+ 子机结束curl→POST /api/agent/script-callback - 执行热数据 Redis(TTL 2h),MySQL 仅 60s 分批刷盘
- 短任务 stop、执行历史页、自动卡住检测(详见平台 changelog)
长任务流程
勾选「长任务」执行脚本时:
- 主站为每台子机生成
job_id+ 一次性secret,写入 Redis(TTL 7 天) - 主站用
nohup包装脚本,脚本结束后在子机执行curl→POST /api/agent/script-callback - 主站更新
script_executions.results,并通过 WebSocket 推送script_job_done
配置要求
.env中必须配置NEXUS_API_BASE_URL(子机可访问的主站 HTTPS 地址),否则长任务接口返回 400
API
| 端点 | 认证 | 说明 |
|---|---|---|
POST /api/scripts/exec |
JWT | 请求体增加 long_task: true |
POST /api/agent/script-callback |
job_id + secret(一次性) |
子机 curl,无需 JWT |
回调 JSON 示例:
{
"job_id": "…",
"server_id": 12,
"secret": "…",
"exit_code": 0,
"message": "done"
}
Redis → MySQL
| 常量 | 值 | 文件 |
|---|---|---|
REDIS_TTL_SECONDS |
7200 | script_execution_store.py |
FLUSH_INTERVAL_SECONDS |
60 | 同上 |
FLUSH_BATCH_LIMIT |
50 | 同上 |
STUCK_NO_PROGRESS_SECONDS |
3600 | 同上 |
- 全部状态变更只写 Redis;读接口优先 Redis
- 后台
script_execution_flush:刷盘 +detect_stuck_executions results._meta.events时间线;audit_logs即时写入
审计 action
execute_started、execute_command、stop_execution、retry_execution、mark_stuck、script_job_callback、auto_stuck、server_auto_stuck
子机 Agent(短任务停止)
| 接口 | 说明 |
|---|---|
POST /exec + wait: false |
返回 pid |
POST /exec/wait |
等待结束 |
POST /exec/kill |
终止进程 |
未升级 Agent 时无法短任务中途停止。
涉及文件
server/application/services/script_jobs.pyserver/application/services/script_job_callback.pyserver/infrastructure/redis/script_execution_store.pyserver/background/script_execution_flush.pyserver/api/agent.pyweb/app/scripts.html、web/app/script-executions.htmlweb/agent/agent.py