temp
This commit is contained in:
@@ -3,20 +3,21 @@ package queue
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"tyc-server/app/main/api/internal/config"
|
||||
"tyc-server/app/main/api/internal/svc"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
const TASKTIME = "0 3 * * *"
|
||||
|
||||
type CleanQueryDataHandler struct {
|
||||
config *config.Config
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCleanQueryDataHandler(svcCtx *svc.ServiceContext) *CleanQueryDataHandler {
|
||||
func NewCleanQueryDataHandler(config *config.Config, svcCtx *svc.ServiceContext) *CleanQueryDataHandler {
|
||||
return &CleanQueryDataHandler{
|
||||
config: config,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
@@ -25,14 +26,10 @@ func (l *CleanQueryDataHandler) ProcessTask(ctx context.Context, t *asynq.Task)
|
||||
now := time.Now().Format("2006-01-02 15:04:05")
|
||||
logx.Infof("%s - 开始执行查询数据清理任务", now)
|
||||
|
||||
// 计算7天前的时间
|
||||
sevenDaysAgo := time.Now().AddDate(0, 0, -7)
|
||||
// 计算15天前的时间
|
||||
sevenDaysAgo := time.Now().AddDate(0, 0, -l.config.CleanTask.Days)
|
||||
|
||||
// 创建查询条件,排除product_id为4的记录
|
||||
conditions := l.svcCtx.QueryModel.SelectBuilder().Where("product_id != ?", 4)
|
||||
|
||||
// 调用QueryModel删除7天前的数据,排除product_id为4的记录
|
||||
result, err := l.svcCtx.QueryModel.DeleteBefore(ctx, sevenDaysAgo, conditions)
|
||||
result, err := l.svcCtx.QueryModel.DeleteBefore(ctx, sevenDaysAgo)
|
||||
if err != nil {
|
||||
logx.Errorf("%s - 清理查询数据失败: %v", time.Now().Format("2006-01-02 15:04:05"), err)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user