为asynq历史任务在redis中添加生命周期,过期时间为订单过期时间

This commit is contained in:
dev
2026-01-27 12:18:32 +08:00
parent 14435ba426
commit 9def1ec447
9 changed files with 55 additions and 18 deletions
+7 -4
View File
@@ -2,6 +2,10 @@ package service
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/assimon/luuu/config"
"github.com/assimon/luuu/model/dao"
"github.com/assimon/luuu/model/data"
@@ -15,9 +19,6 @@ import (
"github.com/dromara/carbon/v2"
"github.com/hibiken/asynq"
"github.com/shopspring/decimal"
"math/rand"
"sync"
"time"
)
const (
@@ -95,7 +96,9 @@ func CreateTransaction(req *request.CreateTransactionRequest) (*response.CreateT
tx.Commit()
// 超时过期消息队列
orderExpirationQueue, _ := handle.NewOrderExpirationQueue(order.TradeId)
mq.MClient.Enqueue(orderExpirationQueue, asynq.ProcessIn(config.GetOrderExpirationTimeDuration()))
mq.MClient.Enqueue(orderExpirationQueue, asynq.ProcessIn(config.GetOrderExpirationTimeDuration()),
asynq.Retention(config.GetOrderExpirationTimeDuration()),
)
ExpirationTime := carbon.Now().AddMinutes(config.GetOrderExpirationTime()).Timestamp()
resp := &response.CreateTransactionResponse{
TradeId: order.TradeId,
+4 -1
View File
@@ -5,6 +5,7 @@ import (
"net/http"
"sync"
"github.com/assimon/luuu/config"
"github.com/spf13/viper"
"github.com/assimon/luuu/model/data"
@@ -139,7 +140,9 @@ func Trc20CallBack(token string, wg *sync.WaitGroup) {
// 回调队列
orderCallbackQueue, _ := handle.NewOrderCallbackQueue(order)
orderNoticeMaxRetry := viper.GetInt("order_notice_max_retry")
mq.MClient.Enqueue(orderCallbackQueue, asynq.MaxRetry(orderNoticeMaxRetry))
mq.MClient.Enqueue(orderCallbackQueue, asynq.MaxRetry(orderNoticeMaxRetry),
asynq.Retention(config.GetOrderExpirationTimeDuration()),
)
// mq.MClient.Enqueue(orderCallbackQueue, asynq.MaxRetry(5))
// 发送机器人消息
msgTpl := `