This commit is contained in:
ziming 2025-11-17 09:38:16 +08:00
parent ef5a80f501
commit d64c8ea435
1 changed files with 47 additions and 19 deletions

View File

@ -6,6 +6,8 @@ import (
"fmt"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/transport/http"
"golang.org/x/sync/errgroup"
"runtime"
"voucher/internal/biz/bo"
"voucher/internal/biz/do"
)
@ -44,10 +46,47 @@ func (this *VoucherBiz) UsedNotify(ctx context.Context, msg string) error {
errNum := 0
return this.OrderRepo.FinUsedInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error {
eg := new(errgroup.Group)
eg.SetLimit(3)
err := this.OrderRepo.FinUsedInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error {
for _, order := range rows {
eg.Go(func() error {
if err := this.usedNotify(ctx, order); err != nil {
errNum++
if errNum > 50 {
return fmt.Errorf("核销重试通知处理,通知失败次数超过50次,请检查:%v", err)
}
log.Warnf("核销重试通知处理,通知失败:%v", err)
}
return nil
})
}
return nil
})
if err != nil {
return err
}
return eg.Wait() // 仅返回第一个错误
}
func (this *VoucherBiz) usedNotify(ctx context.Context, order *bo.OrderBo) error {
defer func() {
if err := recover(); err != nil {
_, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息
log.Errorf("核销重试通知处理,发生错误:req:%s,err:%v,file:%s,line:%d", order.OrderNo, err, file, line)
}
}()
event, err := order.Status.GetOrderNotifyEvent()
if err != nil {
return err
@ -61,16 +100,5 @@ func (this *VoucherBiz) UsedNotify(ctx context.Context, msg string) error {
Type: order.Type,
}
if err = this.request(ctx, order, notify); err != nil {
errNum++
if errNum > 50 {
return fmt.Errorf("核销重试通知处理,通知失败次数超过50次,请检查:%v", err)
}
log.Warnf("核销重试通知处理,通知失败:%v", err)
}
}
return nil
})
return this.request(ctx, order, notify)
}