54 lines
1.7 KiB
Markdown
54 lines
1.7 KiB
Markdown
|
|
# T526 — radar-sweep-model-repository
|
|||
|
|
|
|||
|
|
> Status: `done`
|
|||
|
|
> Milestone: `M2`
|
|||
|
|
> Kind: `feat`
|
|||
|
|
> Est. change: `~140 lines`
|
|||
|
|
|
|||
|
|
## Goal
|
|||
|
|
|
|||
|
|
完成後系統應:RadarSweep 執行紀錄可寫可查,欄位足以回答「命中幾筆、判了幾筆、截斷幾筆、失敗原因、耗多少點」。
|
|||
|
|
|
|||
|
|
## Depends on
|
|||
|
|
|
|||
|
|
- T501
|
|||
|
|
|
|||
|
|
## Inputs
|
|||
|
|
|
|||
|
|
- Spec:`../spec.md` §5.4、§7(可觀測性)、§8
|
|||
|
|
|
|||
|
|
## Outputs
|
|||
|
|
|
|||
|
|
### 程式變更(預期路徑)
|
|||
|
|
|
|||
|
|
| 路徑 | 動作 | 說明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| `apps/backend/internal/module/radar/domain/sweep.go` | add | struct:`watch_id`、`job_id`、`path(api|crawler)`、`hit_count`、`judged_count`、`created_count`、`truncated_count`、`failed_reason?`、`credits_used`、`started_at`、`ended_at`、`judged_external_ids[]` |
|
|||
|
|
| `apps/backend/internal/module/radar/repository/sweep_mongo.go` | add | Create、Update(累加計數)、ListByOwner、GetByJobID |
|
|||
|
|
| `apps/backend/internal/module/radar/repository/sweep_memory.go` | add | 測試用 |
|
|||
|
|
|
|||
|
|
### 行為變更
|
|||
|
|
|
|||
|
|
- 計數為累加更新,Job 中途失敗時已寫入的進度保留(供 T532 續跑判斷)。
|
|||
|
|
- `failed_reason` 為人可讀字串,不含 token 明文。
|
|||
|
|
|
|||
|
|
## Out of scope
|
|||
|
|
|
|||
|
|
- Job 執行流程(T527/T528)
|
|||
|
|
- 列表 API(T533)
|
|||
|
|
|
|||
|
|
## Acceptance
|
|||
|
|
|
|||
|
|
- [x] unit test:建立→累加→查詢,`judged_external_ids` 可去重累加
|
|||
|
|
- [x] 指令:
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd apps/backend && go test ./internal/module/radar/... -count=1
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 實作落點
|
|||
|
|
|
|||
|
|
- `domain/sweep.go`:`RadarSweep`、`SweepDelta`(累加+可選 failed_reason/ended_at)
|
|||
|
|
- `repository/sweep_{memory,mongo}.go`:Create/Update($inc+$addToSet)/GetByJobID/ListByOwner
|
|||
|
|
- 測試:`repository/sweep_memory_test.go`
|