- ExecutionMode enum adds Undecided variant (default for new tasks)
- Webhook creates tasks as Undecided instead of hardcoded SshCli
- Dispatch loop: Phase 1 matches ssh_cli hosts, Phase 2 marks remaining as HttpPull
- Dequeue now returns http_pull AND undecided tasks (atomic claim)
- New endpoint: POST /api/v1/tasks/{id}/assign for coordinator explicit assignment
- Backward compatible: existing SshCli/HttpPull tasks unaffected
- 37 tests passing (6 new)
52 lines
2.2 KiB
Markdown
52 lines
2.2 KiB
Markdown
## 1. 数据模型
|
||
|
||
- [ ] 1.1 `ExecutionMode` enum 新增 `Undecided` 变体
|
||
- [ ] 1.2 Task 默认 execution_mode 改为 `Undecided`
|
||
- [ ] 1.3 DB schema 更新(如需要)
|
||
- [ ] 1.4 单元测试:Undecided 序列化/反序列化
|
||
|
||
## 2. Forgejo Webhook
|
||
|
||
- [ ] 2.1 移除 `forgejo.rs` 中硬编码的 `ExecutionMode::SshCli`
|
||
- [ ] 2.2 改为 `ExecutionMode::Undecided`
|
||
- [ ] 2.3 测试:webhook 创建的任务 execution_mode 为 Undecided
|
||
|
||
## 3. Dispatch Loop 重写
|
||
|
||
- [ ] 3.1 Phase 1:扫描 Undecided 任务,尝试匹配 ssh_cli host
|
||
- 匹配成功 → 标记 SshCli + 执行
|
||
- 匹配失败或 host offline → 保持 Undecided
|
||
- [ ] 3.2 Phase 2:超时未匹配的 Undecided 任务标记为 HttpPull
|
||
- 超时阈值可配置(默认 30s,即 3 个 dispatch cycle)
|
||
- 或者:直接让 dequeue 也能拉 Undecided(更简单)
|
||
- [ ] 3.3 单元测试:两个阶段的各种场景
|
||
- [ ] 3.4 集成测试:混合 ssh_cli + http_pull 环境
|
||
|
||
## 4. Dequeue API 更新
|
||
|
||
- [ ] 4.1 SQL 查询改为 `execution_mode IN ('http_pull', 'undecided')`
|
||
- [ ] 4.2 Dequeue 时原子更新 execution_mode 为 HttpPull(如果原为 Undecided)
|
||
- [ ] 4.3 测试:dequeue Undecided 任务返回 200 + 正确赋值
|
||
|
||
## 5. Coordinator 指派 API
|
||
|
||
- [ ] 5.1 新增 `POST /api/v1/tasks/{id}/assign`
|
||
- 请求体:`{"agent_id": "...", "execution_mode": "..."(可选)}`
|
||
- 自动检测:注册的 http_pull agent → HttpPull,配置的 ssh_cli host → SshCli
|
||
- 错误处理:404(agent 不存在)、400(任务状态不允许)
|
||
- [ ] 5.2 路由注册
|
||
- [ ] 5.3 测试:指派成功、指派失败的各种场景
|
||
|
||
## 6. 文档更新
|
||
|
||
- [ ] 6.1 API 参考新增 assign 端点
|
||
- [ ] 6.2 Skill 更新:dequeue 现在也能拿到 Undecided 任务
|
||
- [ ] 6.3 架构文档更新:两阶段 dispatch 说明
|
||
|
||
## 7. 验证
|
||
|
||
- [ ] 7.1 端到端测试:webhook 创建任务 → dispatch → ssh_cli 执行
|
||
- [ ] 7.2 端到端测试:webhook 创建任务 → 无 ssh_cli 匹配 → http_pull dequeue
|
||
- [ ] 7.3 端到端测试:coordinator 指派 → agent 执行
|
||
- [ ] 7.4 竞争条件测试:dispatch 和 dequeue 同时抢任务
|
||
- [ ] 7.5 向后兼容:已有 SshCli/HttpPull 任务不受影响
|