Files
pay/internal/reconcile/orders.go
T

25 lines
668 B
Go

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
}
}