feat(v2): reconcile Runner 骨架 + 订单级过期清理(超 TTL pending 单/零尝试孤儿单自动关闭)

This commit is contained in:
wangjia
2026-07-10 17:19:38 +08:00
parent aa14204640
commit 6427e8c848
6 changed files with 224 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
package reconcile
import (
"context"
"log"
"time"
"github.com/wangjia/pay/internal/store"
)
// OrderExpirerTask 返回「关闭超 TTL 未付 pending 订单」的周期任务体。
// cutoff = now()-ttl,now 注入(测试确定性);幂等条件 UPDATE(见 store.ExpireStaleOrders)。
func OrderExpirerTask(orders *store.OrderStore, ttl time.Duration, now func() time.Time) func(ctx context.Context) error {
return func(ctx context.Context) error {
n, err := orders.ExpireStaleOrders(now().Add(-ttl), 500)
if err != nil {
return err
}
if n > 0 {
log.Printf("[reconcile] 过期关闭 %d 个超时未付订单(TTL=%s)", n, ttl)
}
return nil
}
}