补齐相关日志日志
This commit is contained in:
@@ -80,10 +80,19 @@ func runVirtualPayConfirm() {
|
||||
lockKey := redismodel.KeyLockVirtualConfirm
|
||||
lockVal := genUUID()
|
||||
ok, lerr := redisdao.TryLock(ctx, lockKey, lockVal, virtualConfirmLockTTL)
|
||||
if lerr != nil || !ok {
|
||||
if lerr != nil {
|
||||
slog.ErrorContext(ctx, "virtual confirm: acquire lock failed", "error", lerr)
|
||||
return
|
||||
}
|
||||
defer redisdao.Unlock(context.Background(), lockKey, lockVal)
|
||||
if !ok {
|
||||
slog.DebugContext(ctx, "virtual confirm: another instance running, skip")
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if uerr := redisdao.Unlock(context.Background(), lockKey, lockVal); uerr != nil {
|
||||
slog.WarnContext(ctx, "virtual confirm: release lock failed", "error", uerr)
|
||||
}
|
||||
}()
|
||||
|
||||
now := nowUnix()
|
||||
orders, err := mysqldao.NewOrderDao().
|
||||
@@ -93,6 +102,7 @@ func runVirtualPayConfirm() {
|
||||
return
|
||||
}
|
||||
if len(orders) == 0 {
|
||||
slog.DebugContext(ctx, "virtual confirm: no unconfirmed orders in window")
|
||||
return
|
||||
}
|
||||
if len(orders) >= virtualConfirmBatchSize {
|
||||
@@ -121,6 +131,7 @@ func runVirtualPayConfirm() {
|
||||
targets = append(targets, &orders[i])
|
||||
}
|
||||
if len(targets) == 0 {
|
||||
slog.DebugContext(ctx, "virtual confirm: all candidates skipped by unpaid cache", "candidates", len(orders))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,7 +150,7 @@ func runVirtualPayConfirm() {
|
||||
defer func() { <-sem }()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
slog.Error("virtual confirm worker panic", "order_no", o.OrderNo, "recover", r)
|
||||
slog.ErrorContext(ctx, "virtual confirm worker panic", "order_no", o.OrderNo, "recover", r)
|
||||
}
|
||||
}()
|
||||
if s.confirmVirtualOrder(ctx, o) {
|
||||
@@ -154,6 +165,9 @@ func runVirtualPayConfirm() {
|
||||
if confirmed > 0 {
|
||||
slog.InfoContext(ctx, "virtual pay confirm compensated orders",
|
||||
"scanned", len(orders), "queried", len(targets), "confirmed", confirmed)
|
||||
} else {
|
||||
slog.DebugContext(ctx, "virtual pay confirm finished without compensation",
|
||||
"scanned", len(orders), "queried", len(targets))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,11 +177,16 @@ func runVirtualPayConfirm() {
|
||||
func (s *OrderService) confirmVirtualOrder(ctx context.Context, order *mysqlmodel.Order) bool {
|
||||
// query_order 需要 openid,订单表不冗余该字段,按 user_id 取。
|
||||
user, err := s.userDao.UserGetByID(ctx, order.UserID)
|
||||
if err != nil || user.WxOpenID == "" {
|
||||
slog.WarnContext(ctx, "virtual confirm: user openid unavailable",
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "virtual confirm: get user failed",
|
||||
"order_no", order.OrderNo, "user_id", order.UserID, "error", err)
|
||||
return false
|
||||
}
|
||||
if user.WxOpenID == "" {
|
||||
slog.WarnContext(ctx, "virtual confirm: user openid unavailable",
|
||||
"order_no", order.OrderNo, "user_id", order.UserID)
|
||||
return false
|
||||
}
|
||||
|
||||
info, qerr := wechat.QueryOrder(ctx, user.WxOpenID, order.OrderNo, "")
|
||||
if qerr != nil {
|
||||
|
||||
Reference in New Issue
Block a user