feat: add err_msg field for mj and sd jobs

This commit is contained in:
RockYang
2024-01-26 14:50:36 +08:00
parent 399cf65fc9
commit 6bd6bb3885
12 changed files with 50 additions and 16 deletions

View File

@@ -86,9 +86,13 @@ func (s *Service) Run() {
}
if err != nil || (res.Code != 1 && res.Code != 22) {
logger.Error("绘画任务执行失败:", err, res.Description)
errMsg := err.Error() + res.Description
logger.Error("绘画任务执行失败:", errMsg)
// update the task progress
s.db.Model(&model.MidJourneyJob{Id: uint(task.Id)}).UpdateColumn("progress", -1)
s.db.Model(&model.MidJourneyJob{Id: uint(task.Id)}).UpdateColumns(map[string]interface{}{
"progress": -1,
"err_msg": errMsg,
})
// 任务失败,通知前端
s.notifyQueue.RPush(task.UserId)
// restore img_call quota

View File

@@ -217,7 +217,10 @@ func (p *ServicePool) SyncTaskProgress() {
}
// 任务失败了
if task.FailReason != "" {
p.db.Model(&model.MidJourneyJob{Id: v.Id}).UpdateColumn("progress", -1)
p.db.Model(&model.MidJourneyJob{Id: v.Id}).UpdateColumns(map[string]interface{}{
"progress": -1,
"err_msg": task.FailReason,
})
continue
}
if len(task.Buttons) > 0 {

View File

@@ -82,9 +82,12 @@ func (s *Service) Run() {
}
if err != nil {
logger.Error("绘画任务执行失败:", err)
logger.Error("绘画任务执行失败:", err.Error())
// update the task progress
s.db.Model(&model.MidJourneyJob{Id: uint(task.Id)}).UpdateColumn("progress", -1)
s.db.Model(&model.MidJourneyJob{Id: uint(task.Id)}).UpdateColumns(map[string]interface{}{
"progress": -1,
"err_msg": err.Error(),
})
s.notifyQueue.RPush(task.UserId)
// restore img_call quota
if task.Type.String() != types.TaskUpscale.String() {

View File

@@ -68,9 +68,12 @@ func (s *Service) Run() {
logger.Infof("%s handle a new Stable-Diffusion task: %+v", s.name, task)
err = s.Txt2Img(task)
if err != nil {
logger.Error("绘画任务执行失败:", err)
logger.Error("绘画任务执行失败:", err.Error())
// update the task progress
s.db.Model(&model.SdJob{Id: uint(task.Id)}).UpdateColumn("progress", -1)
s.db.Model(&model.SdJob{Id: uint(task.Id)}).UpdateColumns(map[string]interface{}{
"progress": -1,
"err_msg": err.Error(),
})
// restore img_call quota
s.db.Model(&model.User{}).Where("id = ?", task.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls + ?", 1))
// release task num
@@ -300,7 +303,10 @@ func (s *Service) callback(data CBReq) {
} else { // 任务失败
logger.Error("任务执行失败:", data.Message)
// update the task progress
s.db.Model(&model.SdJob{Id: uint(data.JobId)}).UpdateColumn("progress", -1)
s.db.Model(&model.SdJob{Id: uint(data.JobId)}).UpdateColumns(map[string]interface{}{
"progress": -1,
"err_msg": data.Message,
})
// restore img_calls
s.db.Model(&model.User{}).Where("id = ? AND img_calls > 0", data.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls + ?", 1))
}

View File

@@ -15,8 +15,9 @@ type MidJourneyJob struct {
Hash string // message hash
Progress int
Prompt string
UseProxy bool // 是否使用反代加载图片
Publish bool //是否发布图片到画廊
UseProxy bool // 是否使用反代加载图片
Publish bool //是否发布图片到画廊
ErrMsg string // 报错信息
CreatedAt time.Time
}

View File

@@ -11,7 +11,8 @@ type SdJob struct {
Progress int
Prompt string
Params string
Publish bool //是否发布图片到画廊
Publish bool //是否发布图片到画廊
ErrMsg string // 报错信息
CreatedAt time.Time
}

View File

@@ -17,5 +17,6 @@ type MidJourneyJob struct {
Prompt string `json:"prompt"`
UseProxy bool `json:"use_proxy"`
Publish bool `json:"publish"`
ErrMsg string `json:"err_msg"`
CreatedAt time.Time `json:"created_at"`
}

View File

@@ -15,5 +15,6 @@ type SdJob struct {
Progress int `json:"progress"`
Prompt string `json:"prompt"`
Publish bool `json:"publish"`
ErrMsg string `json:"err_msg"`
CreatedAt time.Time `json:"created_at"`
}