refactor(service): improve tracing and filtering in order notify delay queue
- Rename tracing spans for better clarity with "CreateOrderDelayQueueTicker" context - Add status filter "wait" to notify query parameters - Remove nested goroutine and simplify tracing context usage - Replace notifyPool.Go with direct call to SendOrderNotify for each task - Adjust tracing span attribute key and reuse span variable to reduce complexity
This commit is contained in:
@@ -150,17 +150,18 @@ func CreateOrderDelayQueue(ctx context.Context) {
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
func() {
|
||||
linkCtx, span := otelTrace.Span(context.Background(), "CreateOrderDelayQueue", "CreateOrderDelayQueue")
|
||||
linkCtx, span := otelTrace.Span(context.Background(), "CreateOrderDelayQueueTicker", "CreateOrderDelayQueue.ticker")
|
||||
defer span.End()
|
||||
params := make(map[string]any)
|
||||
params["times__lte"] = consts.LimitTimes
|
||||
params["create_time__gte"] = utils.GetDateTimeBeforeHours(24)
|
||||
params["create_time__lte"] = time.Now().Add(-time.Minute * 2)
|
||||
params["status"] = "wait"
|
||||
notifyList := notify.GetNotifyInfosNotSuccess(linkCtx, params)
|
||||
for _, nf := range notifyList {
|
||||
func() {
|
||||
linkCtx2, span2 := otelTrace.Span(linkCtx, "CreateOrderDelayQueue", "CreateOrderDelayQueue", trace.WithAttributes(attribute.String("bankOrderId", nf.BankOrderId)))
|
||||
defer span2.End()
|
||||
ctx, span = otelTrace.Span(linkCtx, "CreateOrderDelayQueueTicker", "CreateOrderDelayQueue.ctxGo", trace.WithAttributes(attribute.String("bankOrderId", nf.BankOrderId)))
|
||||
defer span.End()
|
||||
minute := GetOrderNotifyMinute(nf.Times)
|
||||
task := OrderNotifyTask{
|
||||
Delay: time.NewTimer(time.Duration(minute) * time.Minute),
|
||||
@@ -171,11 +172,7 @@ func CreateOrderDelayQueue(ctx context.Context) {
|
||||
LimitTimes: consts.LimitTimes,
|
||||
Status: nf.Status,
|
||||
}
|
||||
notifyPool.Go(func() {
|
||||
linkCtx3, span3 := otelTrace.Span(linkCtx2, "CreateOrderDelayQueue", "CreateOrderDelayQueue", trace.WithAttributes(attribute.String("bankOrderId", nf.BankOrderId)))
|
||||
defer span3.End()
|
||||
OrderNotifyTimer(linkCtx3, task)
|
||||
})
|
||||
SendOrderNotify(ctx, task.BankOrderId)
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user