fix(v2): 退款自愈扫描加回溯窗(防 LIMIT 尾部饥饿)+ 清死行
RefundApplyTask 的候选查询按 out_trade_no ASC/id ASC 取前 200,succeeded 退款历史 只增不减、partially_refunded 长期驻留,超过 limit 后最新的崩溃窗口永远排在候选外 扫不到。两路查询都加 since 回溯窗:RefundStore.ListDistinctOutTradeNosByStatusSince (completed_at>=since)、OrderStore.ListOrdersByStatusSince(updated_at>=since),旧的 无窗方法原样保留。RefundApplyTask 新增 lookback/now 参数,config.ReconcileConfig 新增 RefundApplyLookbackMin(默认 48h)。顺带按 T6 复审补 OrderTTLMin 字段注释(须 ≫ crypto orderTTL 15min),清 sync_test.go 死行 `_ = time.Second`。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
This commit is contained in:
+6
-1
@@ -102,7 +102,7 @@ type QuerySyncConfig struct {
|
||||
// ReconcileConfig v2 后台守护/对账周期任务开关与间隔。
|
||||
type ReconcileConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
OrderTTLMin int `mapstructure:"order_ttl_min"` // pending 订单存活 TTL(分钟),超则关闭
|
||||
OrderTTLMin int `mapstructure:"order_ttl_min"` // pending 订单存活 TTL(分钟),超则关闭;须 ≫ crypto 支付窗 orderTTL(15min,internal/provider/crypto/crypto.go)——否则在途 crypto 支付可能被订单级过期误杀
|
||||
ExpireEverySec int `mapstructure:"expire_every_sec"` // 过期清理间隔
|
||||
SyncEverySec int `mapstructure:"sync_every_sec"` // 查单对账间隔
|
||||
UsageEverySec int `mapstructure:"usage_every_sec"` // 用量快照刷新间隔
|
||||
@@ -114,6 +114,10 @@ type ReconcileConfig struct {
|
||||
// 本期归到本任务(对账主体)一起装配,brief 原表未列。
|
||||
RefundApplyEverySec int `mapstructure:"refund_apply_every_sec"` // 退款修复扫描 + 卡滞告警 共用间隔
|
||||
RefundStuckWarnMin int `mapstructure:"refund_stuck_warn_min"` // 退款卡滞 processing/manual_pending 告警阈值(分钟)
|
||||
// RefundApplyLookbackMin 退款修复扫描的候选回溯窗(分钟):只扫 completed_at/updated_at
|
||||
// 落在 [now-lookback, now] 内的候选,防 LIMIT 尾部饥饿(见 store.ListDistinctOutTradeNosByStatusSince
|
||||
// / ListOrdersByStatusSince)。默认 48 小时——自愈针对近期崩溃窗口,历史一致性由已收敛状态保证。
|
||||
RefundApplyLookbackMin int `mapstructure:"refund_apply_lookback_min"`
|
||||
}
|
||||
|
||||
var C Config
|
||||
@@ -159,6 +163,7 @@ func Load() {
|
||||
viper.SetDefault("reconcile.orphan_window_min", 180)
|
||||
viper.SetDefault("reconcile.refund_apply_every_sec", 300)
|
||||
viper.SetDefault("reconcile.refund_stuck_warn_min", 30)
|
||||
viper.SetDefault("reconcile.refund_apply_lookback_min", 48*60)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Println("[config] 未找到 config.yaml,使用默认值 + 环境变量")
|
||||
|
||||
Reference in New Issue
Block a user