🐛 任务执行bug和日志

This commit is contained in:
sugarBecomer
2025-11-07 01:14:10 +08:00
parent ae9984460f
commit e4d07874eb
4 changed files with 39 additions and 4 deletions
+6 -1
View File
@@ -37,4 +37,9 @@ fromName = "今日校园系统"
accessKey = "dzckoE1UlZe8XFItWQDI"
secretKey = "f8UZdnDohtwZk5HInT1Cw1QCztSGnFuPPqfSSjzu"
baseUrl = "http://s3.out"
bucket = "likedream"
bucket = "likedream"
[cpdaily]
appVersion = "5.7.0"
systemVersion = "iOS 17"
calVersion = "3.0.0"
@@ -605,9 +605,9 @@ func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[str
} else {
// 否则,填充查寝其他参数
if signInstanceWidVar := rows["signInstanceWid"]; signInstanceWidVar != nil {
resultForm["signInstanceWid"] = gvar.New(signInstanceWidVar.String())
resultForm["SignInstanceWid"] = gvar.New(signInstanceWidVar.String())
} else {
resultForm["signInstanceWid"] = gvar.New("")
resultForm["SignInstanceWid"] = gvar.New("")
}
// 查找 isMalposition 参数
+27
View File
@@ -0,0 +1,27 @@
package errors
import (
"errors"
"testing"
)
func TestBusinessError(t *testing.T) {
defer func() {
if err := recover(); err != nil {
of, b := Of[*BusinessError](err.(error))
t.Log(of, b)
t.Log("ok")
}
}()
err := NewBusinessError(503, "调试错误")
panic(err)
}
func Of[T error](input error) (T, bool) {
var ret T
if errors.As(input, &ret) {
return ret, true
}
return ret, false
}
@@ -8,6 +8,7 @@ import (
"likedream-goframe/internal/application/cpdaily/school"
task2 "likedream-goframe/internal/application/cpdaily/task"
"likedream-goframe/internal/application/cpdaily/task/formtype"
errors2 "likedream-goframe/internal/common/errors"
"likedream-goframe/internal/db"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/ent/cptask"
@@ -57,6 +58,8 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
if e1, ok := utils.Of[*errors.BusinessError](err); ok {
errorMessage = e1.Message()
} else if e1, ok := utils.Of[*errors2.BusinessError](err); ok {
errorMessage = e1.Message
} else {
errorMessage = "未知的错误导致任务执行失败"
}
@@ -68,7 +71,7 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
SetIsSuccess(false).
SetRealName("").
SetErrorMessage(errorMessage).
Exec(ctx)
Exec(context.Background())
utils.LogError(ctx, "创建任务日志失败", oops.With("task_id", taskPayload.CpTaskID).Wrap(e))