fix: 任务处理返回信息和错误error对象

This commit is contained in:
TsMask
2023-10-21 16:11:53 +08:00
parent 2c262e1e7d
commit bdc6fdaa89
5 changed files with 26 additions and 16 deletions

View File

@@ -63,7 +63,9 @@ type Queue struct {
// QueueProcessor 队列处理函数接口
type QueueProcessor interface {
// Execute 实际执行函数
Execute(data any) any
// any 返回有效值最终序列化为字符串,记录为成功
// error 存在错误,记录为失败
Execute(data any) (any, error)
}
// RunJob 运行任务data是传入的数据
@@ -196,7 +198,12 @@ func (s QueueJob) Run() {
// 获取队列处理器接口实现
processor := *job.queueProcessor
result := processor.Execute(job.Data)
job.Status = Completed
newLog.Completed(result, "completed", job)
result, err := processor.Execute(job.Data)
if err != nil {
job.Status = Failed
newLog.Error(err, "failed", job)
} else {
job.Status = Completed
newLog.Completed(result, "completed", job)
}
}