From 1323bc7aa8b38aa18694be41897baab125210f56 Mon Sep 17 00:00:00 2001 From: sugarBecomer Date: Sat, 8 Nov 2025 21:47:08 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E7=AD=BE=E5=88=B0=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?&=20=E5=AE=9A=E6=97=B6=E9=87=8D=E7=BD=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/application/classifier/classifier.go | 2 +- .../application/cpdaily/task/collection.go | 6 +++--- internal/application/cpdaily/task/sign.go | 18 +++++++++--------- internal/cst/task.go | 6 ++++-- internal/framework/schedule/init.go | 5 +++++ internal/framework/schedule/scanner.go | 2 +- internal/framework/schedule/server.go | 4 +++- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/internal/application/classifier/classifier.go b/internal/application/classifier/classifier.go index 57b5f74..55586bb 100644 --- a/internal/application/classifier/classifier.go +++ b/internal/application/classifier/classifier.go @@ -45,7 +45,7 @@ func NewImageClassifier(modelPath, classesPath string) (*ImageClassifier, error) ort.SetSharedLibraryPath(dir) err = ort.InitializeEnvironment() if err != nil { - logger.Logger.Info("初始化onnx:", zap.String("绝对路径", absPath), zap.String("父文件夹", dir)) + logger.Logger.Error("初始化onnx:", zap.String("绝对路径", absPath), zap.String("父文件夹", dir)) return nil, fmt.Errorf("初始化ONNX Runtime失败: %v", err) } diff --git a/internal/application/cpdaily/task/collection.go b/internal/application/cpdaily/task/collection.go index 00a3a2f..a1a3320 100644 --- a/internal/application/cpdaily/task/collection.go +++ b/internal/application/cpdaily/task/collection.go @@ -161,7 +161,7 @@ func (c *CpdailyCollectionTask) QueryFormByTitle(ctx context.Context, titleGlob } if matchTask == nil { - utils.OkOrPanic(errors.NewBusinessError(404, fmt.Sprintf("未找到表单信息: %s", titleGlob)), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, fmt.Sprintf("未找到表单信息: %s", titleGlob)), func(err error) error { return oops.With("host", c.host). In("CpdailyCollectionTask.QueryFormByTitle"). Wrap(err) @@ -196,7 +196,7 @@ func (c *CpdailyCollectionTask) QueryFormByTitle(ctx context.Context, titleGlob detailDatas := detailJSON["datas"].MapStrVar() if len(detailDatas) == 0 { - utils.OkOrPanic(errors.NewBusinessError(404, "未找到表单数据"), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, "未找到表单数据"), func(err error) error { return oops.With("host", c.host). In("CpdailyCollectionTask.QueryFormByTitle"). With("titleGlob", titleGlob). @@ -230,7 +230,7 @@ func (c *CpdailyCollectionTask) QueryFormByTitle(ctx context.Context, titleGlob formDatas := formJSON["datas"].MapStrVar() if len(formDatas) == 0 { - utils.OkOrPanic(errors.NewBusinessError(404, "未找到表单数据"), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, "未找到表单数据"), func(err error) error { return oops.With("host", c.host). In("CpdailyCollectionTask.QueryFormByTitle"). With("titleGlob", titleGlob). diff --git a/internal/application/cpdaily/task/sign.go b/internal/application/cpdaily/task/sign.go index 02e9cbf..329c718 100644 --- a/internal/application/cpdaily/task/sign.go +++ b/internal/application/cpdaily/task/sign.go @@ -147,8 +147,8 @@ func (c *CpdailyAutoSignTask) QueryFormByTitle(ctx context.Context, titleGlob st findMatchTitle := func(jsonArr []any) map[string]*gvar.Var { for _, rawJson := range jsonArr { - item, ok := rawJson.(map[string]*gvar.Var) - if !ok { + item := gvar.New(rawJson).MapStrVar() + if len(item) == 0 { continue } taskName, exist := item["taskName"] @@ -178,7 +178,7 @@ func (c *CpdailyAutoSignTask) QueryFormByTitle(ctx context.Context, titleGlob st if matchTask == nil { matchTask = findMatchTitle(signedTasks) if matchTask == nil { - utils.OkOrPanic(errors.NewBusinessError(404, fmt.Sprintf("任务未找到: %s", titleGlob)), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, fmt.Sprintf("任务未找到: %s", titleGlob)), func(err error) error { return oops.With("host", c.host). In("CpdailyAutoSignTask.QueryFormByTitle"). Wrap(err) @@ -210,7 +210,7 @@ func (c *CpdailyAutoSignTask) QueryFormByTitle(ctx context.Context, titleGlob st formDatas := detailResponseJSON["datas"].MapStrVar() if len(formDatas) == 0 { - utils.OkOrPanic(errors.NewBusinessError(404, "任务数据为空"), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, "任务数据为空"), func(err error) error { return oops.With("host", c.host). In("CpdailyAutoSignTask.QueryFormByTitle"). With("titleGlob", titleGlob). @@ -293,7 +293,7 @@ func (c *CpdailyAutoSignTask) QueryFormByYearMonth(ctx context.Context, titleGlo if matchTask == nil { matchTask = findMatchTitle(signedTasks) if matchTask == nil { - utils.OkOrPanic(errors.NewBusinessError(404, fmt.Sprintf("任务未找到: %s", titleGlob)), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, fmt.Sprintf("任务未找到: %s", titleGlob)), func(err error) error { return oops. With("host", c.host). With("year", year). @@ -332,7 +332,7 @@ func (c *CpdailyAutoSignTask) QueryFormByYearMonth(ctx context.Context, titleGlo formDatas := detailResponseJSON["datas"].MapStrVar() if len(formDatas) == 0 { - utils.OkOrPanic(errors.NewBusinessError(404, "任务数据为空"), func(err error) error { + utils.OkOrPanic(errors.NewBusinessError(503, "任务数据为空"), func(err error) error { return oops. With("host", c.host). With("year", year). @@ -379,12 +379,12 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str dto = &formtype.CpTaskFormItem{ Title: "签到具体地址", ColName: "address", - Type: formtype.ItemTypeAddress, + Type: formtype.ItemTypeInput, Required: true, } list = append(list, dto) - var current uint + var current uint = 1 if isPhoto := rows["isPhoto"]; isPhoto != nil && isPhoto.Int() == 1 { dto = &formtype.CpTaskFormItem{ @@ -539,7 +539,7 @@ func (c *CpdailyAutoSignTask) FillCustomForm(ctx context.Context, form map[strin previewUrl := imageuploader.UploadImageFromStorage(ctx, c.host, imageId, types.TaskTypeSign, c.client) - resultForm["signImg"] = gvar.New(previewUrl) + resultForm["signPhotoUrl"] = gvar.New(previewUrl) } // 处理验证码 diff --git a/internal/cst/task.go b/internal/cst/task.go index 3334001..2620cac 100644 --- a/internal/cst/task.go +++ b/internal/cst/task.go @@ -1,9 +1,11 @@ package cst const ( - TaskCpdaily = "task:cpdaily" - TaskEmail = "task:email" + TaskCpdaily = "task:cpdaily" + TaskEmail = "task:email" + TaskResetDaily = "task:reset:daily" TaskQueueCpdaily = "queue:cpdaily" TaskQueueEmail = "queue:email" + TaskQueueDefault = "default" ) diff --git a/internal/framework/schedule/init.go b/internal/framework/schedule/init.go index 541c9aa..2aab647 100644 --- a/internal/framework/schedule/init.go +++ b/internal/framework/schedule/init.go @@ -14,12 +14,17 @@ func Init(ctx context.Context) { initServer(ctx) initInspector(ctx) initScanner() + initPeriodicTasks(ctx) } func Stop() { globalScanner.StopScan() g.Log().Info(gctx.GetInitCtx(), "task scanner stopped") + if globalPeriodicTaskManager != nil { + globalPeriodicTaskManager.Shutdown() + } + e := queue.GetClient().Close() utils.OkOrPanic(e) g.Log().Info(gctx.GetInitCtx(), "asynq client closed") diff --git a/internal/framework/schedule/scanner.go b/internal/framework/schedule/scanner.go index d12f9b9..318b239 100644 --- a/internal/framework/schedule/scanner.go +++ b/internal/framework/schedule/scanner.go @@ -116,7 +116,7 @@ func (ts *TaskScanner) scanCpdailyTask() { e = utils.Catch(func() { queue.AddTask(ts.ctx, asynq.NewTask(cst.TaskCpdaily, payloadWriter.Bytes()), - asynq.TaskID(fmt.Sprintf("cpdaily:task:%d", task.ID)), + asynq.TaskID(fmt.Sprintf("cpdaily:task:schedule:%d", task.ID)), asynq.MaxRetry(3), asynq.Unique(10*time.Second), asynq.ProcessAt(execTime), diff --git a/internal/framework/schedule/server.go b/internal/framework/schedule/server.go index c64be13..3607522 100644 --- a/internal/framework/schedule/server.go +++ b/internal/framework/schedule/server.go @@ -30,7 +30,8 @@ func initServer(ctx context.Context) { ErrorHandler: taskErrorHandler{}, Queues: map[string]int{ cst.TaskQueueEmail: 2, - cst.TaskQueueCpdaily: 8, + cst.TaskQueueCpdaily: 10, + cst.TaskQueueDefault: 1, }, }) @@ -38,6 +39,7 @@ func initServer(ctx context.Context) { mux.Handle(cst.TaskCpdaily, &CpdailyTaskHandler{}) mux.Handle(cst.TaskEmail, &EmailTaskHandler{}) + mux.Handle(cst.TaskResetDaily, &ResetTaskHandler{}) e := globalServer.Start(mux) utils.OkOrPanic(e)