feat(v2): reconcile Runner 骨架 + 订单级过期清理(超 TTL pending 单/零尝试孤儿单自动关闭)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user