fix(v2): Runner interval<=0 守卫(skip+WARN)+ 启动预热只跑本地 job(网络型交 ticker 首跳)

- Task 加 Local 字段;interval<=0 时 Add/AddLocal 跳过注册 + WARN 日志(NewTicker(<=0)
  会 panic,Start 的 per-tick recover 覆盖不到该行)。
- 新增 AddLocal/RunOnceLocal:main.go 启动预热改跑 RunOnceLocal,只同步执行纯 DB 任务
  (order-expire/usage-refresh/refund-apply-sweep/refund-stuck-alert);出网 HTTP 的
  sync-pending/paid-spotcheck/crypto-orphan-scan 交各自 ticker 首跳,不再拖住服务启动。
This commit is contained in:
wangjia
2026-07-10 18:12:35 +08:00
parent 9117de7dcf
commit f310c58767
3 changed files with 127 additions and 12 deletions
+10 -8
View File
@@ -68,23 +68,25 @@ func main() {
rc := config.C.Reconcile
refundStore := store.NewRefundStore(db)
runner := reconcile.NewRunner()
runner.Add("order-expire", time.Duration(rc.ExpireEverySec)*time.Second,
// 纯本地(DB-only)任务用 AddLocal:会被启动预热 RunOnceLocal 同步跑一遍。
runner.AddLocal("order-expire", time.Duration(rc.ExpireEverySec)*time.Second,
reconcile.OrderExpirerTask(orderStore, time.Duration(rc.OrderTTLMin)*time.Minute, time.Now))
runner.Add("usage-refresh", time.Duration(rc.UsageEverySec)*time.Second,
runner.AddLocal("usage-refresh", time.Duration(rc.UsageEverySec)*time.Second,
reconcile.RefreshUsageTask(usage))
runner.AddLocal("refund-apply-sweep", time.Duration(rc.RefundApplyEverySec)*time.Second,
reconcile.RefundApplyTask(orderStore, refundStore, time.Duration(rc.RefundApplyLookbackMin)*time.Minute, time.Now, 200))
runner.AddLocal("refund-stuck-alert", time.Duration(rc.RefundApplyEverySec)*time.Second,
reconcile.RefundStuckAlertTask(refundStore, time.Duration(rc.RefundStuckWarnMin)*time.Minute, time.Now))
// 网络型(出网 HTTP,10-15s 超时)任务用 Add:启动预热不跑,交各自 ticker 首跳。
runner.Add("sync-pending", time.Duration(rc.SyncEverySec)*time.Second,
reconcile.SyncPendingTask(gw, 100))
runner.Add("paid-spotcheck", time.Duration(rc.SpotCheckEverySec)*time.Second,
reconcile.PaidSpotCheckTask(orderStore, pReg, time.Duration(rc.SpotCheckWindowMin)*time.Minute, time.Now))
runner.Add("refund-apply-sweep", time.Duration(rc.RefundApplyEverySec)*time.Second,
reconcile.RefundApplyTask(orderStore, refundStore, time.Duration(rc.RefundApplyLookbackMin)*time.Minute, time.Now, 200))
runner.Add("refund-stuck-alert", time.Duration(rc.RefundApplyEverySec)*time.Second,
reconcile.RefundStuckAlertTask(refundStore, time.Duration(rc.RefundStuckWarnMin)*time.Minute, time.Now))
orphanStore := store.NewOrphanStore(db)
reconcile.AddCryptoJobs(runner, pReg, acctReg, orderStore, orphanStore, rc) // crypto 预留冷启动 Warm + 孤儿扫描(Task 6)
reconcile.AddCryptoJobs(runner, pReg, acctReg, orderStore, orphanStore, rc) // crypto 预留冷启动 Warm(直跑,不受影响)+ 孤儿扫描(网络型,交 ticker 首跳)
ctx := context.Background()
runner.RunOnce(ctx) // 启动预热:先跑一遍(usage 快照/过期清理/退款自愈/crypto Warm 立即生效)
runner.RunOnceLocal(ctx) // 启动预热:只跑本地任务(usage 快照/过期清理/退款自愈立即生效);网络型任务(sync-pending/paid-spotcheck/crypto-orphan-scan)交各自 ticker 首跳,避免上游慢拖住 r.Run(addr) 前的启动
runner.Start(ctx)
log.Printf("[reconcile] 后台守护已启动(过期清理/用量刷新/查单对账/已付抽查/退款修复扫描/退款卡滞告警/crypto 孤儿扫描)")
}