From 59559f42018b14af8db9b0c3f8dc7242c921e17e Mon Sep 17 00:00:00 2001 From: RecordingTheSmile <17124941+RecordingTheSmile@users.noreply.github.com> Date: Fri, 14 Nov 2025 22:26:10 +0800 Subject: [PATCH] fix: task id unique --- internal/application/httpclient/cpdaily.go | 5 +++-- internal/framework/schedule/scanner.go | 5 ++--- internal/service/cpdaily/cptask.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/application/httpclient/cpdaily.go b/internal/application/httpclient/cpdaily.go index 65dd7a2..7f669f5 100644 --- a/internal/application/httpclient/cpdaily.go +++ b/internal/application/httpclient/cpdaily.go @@ -10,11 +10,12 @@ import ( var Cpdaily = resty.New(). SetCookieJar(nil). - SetTimeout(30 * time.Second). + SetTimeout(30*time.Second). SetDoNotParseResponse(true). SetTLSClientConfig(&tls.Config{ InsecureSkipVerify: true, - }) + }). + SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36") func init() { if !utils.IsDebug() { diff --git a/internal/framework/schedule/scanner.go b/internal/framework/schedule/scanner.go index 880c6ae..eed9b53 100644 --- a/internal/framework/schedule/scanner.go +++ b/internal/framework/schedule/scanner.go @@ -5,7 +5,6 @@ import ( "context" "encoding/gob" "errors" - "fmt" cst2 "likedream-goframe/internal/common/cst" "likedream-goframe/internal/common/db" "likedream-goframe/internal/ent" @@ -124,10 +123,10 @@ func (ts *TaskScanner) scanCpdailyTask() { e = utils.Catch(func() { queue.AddTask(ts.ctx, asynq.NewTask(cst2.TaskCpdaily, payloadWriter.Bytes()), - asynq.TaskID(fmt.Sprintf(cst2.TaskCpdailyId, task.ID)), + asynq.Unique(20*time.Minute), asynq.MaxRetry(4), asynq.ProcessAt(execTime), - asynq.Deadline(execTime.Add(10*time.Minute)), + asynq.Timeout(10*time.Minute), asynq.Queue(cst2.TaskQueueCpdaily), ) // 更新未开始的任务状态为队列中 diff --git a/internal/service/cpdaily/cptask.go b/internal/service/cpdaily/cptask.go index 0446aae..ebcd6d4 100644 --- a/internal/service/cpdaily/cptask.go +++ b/internal/service/cpdaily/cptask.go @@ -260,10 +260,10 @@ func (v CpTaskServiceV1) ExecuteNow(ctx context.Context, req *v1.ExecuteNowReq) // 使用时间戳生成唯一的 TaskID,避免与自动扫描的任务冲突,也避免 Unique 限制 // 由于已经检查了任务状态,不需要使用 Unique 来防重复 - taskID := fmt.Sprintf("cpdaily:task:manual:%d:%d", req.Id, time.Now().UnixNano()) + //taskID := fmt.Sprintf("cpdaily:task:manual:%d:%d", req.Id, time.Now().UnixNano()) e = utils.Catch(func() { queue.AddTask(ctx, asynq.NewTask(cst2.TaskCpdaily, payloadWriter.Bytes()), - asynq.TaskID(taskID), + asynq.Unique(20*time.Minute), asynq.Unique(5*time.Second), asynq.MaxRetry(0), asynq.Timeout(10*time.Minute),