fix(reconcile): 修好漂移不再算失败

`-counters` 的职责就是修。修到了说明它起作用了,不是失败。
旧实现把 `fixed > 0` 并进 `failed`,于是"修好 3 条"与"连不上库"返回同一个退出码。
定时任务因此天天告警,告警本身失去意义。
现在只有 `err != nil` 才 `exit 1`。修复条数走日志的 `fixed=N`。
`-verify` 保持不变:它是只读检查,有漂移就是 `exit 1`。

验证:go test -count=1 ./cmd/reconcile/ 全绿;实跑 -counters 修好 1 条返回 exit 0
This commit is contained in:
2026-11-01 16:25:14 +08:00
parent 9d9fdb91e5
commit d542968ed4
2 changed files with 50 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"time"
@@ -48,8 +49,9 @@ func main() {
if *counters {
checked, fixed, err := video.NewCounterReconciler(gormDB).Reconcile(ctx, *limit)
log.Printf("reconcile: checked=%d fixed=%d err=%v", checked, fixed, err)
if err != nil || fixed > 0 {
res := countersResult{checked: checked, fixed: fixed, err: err}
log.Printf("reconcile: %s", res)
if res.failed() {
failed = true
}
}
@@ -77,6 +79,21 @@ func main() {
}
}
// countersResult 是一次 -counters 巡检的结果。
type countersResult struct {
checked int
fixed int
err error
}
// failed 只反映"巡检做没做成"。修好漂移不算失败:-counters 的职责就是修,
// 修到了说明它起作用了。需要"有没有漂移"这个只读信号时用 -verify。
func (r countersResult) failed() bool { return r.err != nil }
func (r countersResult) String() string {
return fmt.Sprintf("checked=%d fixed=%d err=%v", r.checked, r.fixed, r.err)
}
// resolveWindow 解析 [from, to) 窗口。空串取默认值:最近 60 分钟,
// 右端是本分钟起点——这一分钟还在增长,不能当桶(N6)。
func resolveWindow(from, to string, now time.Time) (fromT, toT time.Time) {