优化任务管理

This commit is contained in:
ryan
2026-06-10 20:06:41 +08:00
parent db163034c0
commit e6a6182a0c
6 changed files with 20 additions and 35 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ const (
errCreateTaskExecutionFailed = "创建任务执行记录失败: %w"
errTaskEnqueueFailed = "任务入队失败: %w"
errTaskExecutionNotFound = "任务执行记录不存在: %w"
errRetryOnlyFailedTask = "只有失败的任务才能重试,当前状态: %s"
errRetryOnlyFinishedTask = "只有非进行中的任务才能重试,当前状态: %s"
errTaskNotRetryable = "该任务不支持重试"
errTaskMaxRetryExceeded = "已达到最大重试次数 %d"
errCreateRetryExecutionFailed = "创建重试任务执行记录失败: %w"
+3 -2
View File
@@ -138,8 +138,8 @@ func RetryTask(ctx context.Context, id uint64) (string, error) {
return "", fmt.Errorf(errTaskExecutionNotFound, err)
}
if execution.Status != model.TaskExecutionStatusFailed {
return "", fmt.Errorf(errRetryOnlyFailedTask, execution.Status)
if execution.Status == model.TaskExecutionStatusPending || execution.Status == model.TaskExecutionStatusRunning {
return "", fmt.Errorf(errRetryOnlyFinishedTask, execution.Status)
}
if !execution.Retryable {
@@ -299,6 +299,7 @@ func completeTaskExecution(ctx context.Context, execution *model.TaskExecution,
span.RecordError(execErr)
} else {
execution.Status = model.TaskExecutionStatusSucceeded
execution.ErrorMessage = "" // 清除历史重试失败遗留的错误信息
if result != nil {
execution.Result = result.Message
if result.Detail != "" {