修复程序启动时执行历史没有正确刷新
This commit is contained in:
@@ -191,44 +191,17 @@ func (app *Application) initializePendingTasks(
|
||||
|
||||
// 阶段二:清理所有待执行任务和相关日志
|
||||
logger.Info("阶段二:开始清理所有待执行任务和相关日志...")
|
||||
pendingTasks, err := pendingTaskRepo.FindAllPendingTasks()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取待执行任务失败: %w", err)
|
||||
|
||||
// 直接调用新的方法来更新计划执行日志状态为失败
|
||||
if err := executionLogRepo.FailAllIncompletePlanExecutionLogs(); err != nil {
|
||||
logger.Errorf("更新所有未完成计划执行日志状态为失败失败: %v", err)
|
||||
// 这是一个非阻塞性错误,继续执行
|
||||
}
|
||||
|
||||
var taskLogIDsToCancel []uint
|
||||
var planLogIDsToFail []uint
|
||||
|
||||
for _, pt := range pendingTasks {
|
||||
// 确保 Task 和 TaskExecutionLog 已预加载
|
||||
if pt.Task == nil || pt.TaskExecutionLog.ID == 0 { // TaskExecutionLog.ID为零说明没加载
|
||||
logger.Warnf("待执行任务 %d 缺少关联的 Task 或 TaskExecutionLog,跳过处理。", pt.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
// 收集任务执行日志ID,所有未完成的任务都标记为取消
|
||||
taskLogIDsToCancel = append(taskLogIDsToCancel, pt.TaskExecutionLog.ID)
|
||||
|
||||
// 收集计划执行日志ID
|
||||
if pt.TaskExecutionLog.PlanExecutionLogID != 0 {
|
||||
planLogIDsToFail = append(planLogIDsToFail, pt.TaskExecutionLog.PlanExecutionLogID)
|
||||
}
|
||||
}
|
||||
|
||||
// 批量更新 TaskExecutionLog 状态为取消
|
||||
if len(taskLogIDsToCancel) > 0 {
|
||||
if err := executionLogRepo.UpdateTaskExecutionLogStatusByIDs(taskLogIDsToCancel, models.ExecutionStatusCancelled); err != nil {
|
||||
logger.Errorf("批量更新任务执行日志状态为取消失败: %v", err)
|
||||
// 这是一个非阻塞性错误,继续执行
|
||||
}
|
||||
}
|
||||
|
||||
// 批量更新 PlanExecutionLog 状态为失败
|
||||
if len(planLogIDsToFail) > 0 {
|
||||
if err := executionLogRepo.UpdatePlanExecutionLogsStatusByIDs(planLogIDsToFail, models.ExecutionStatusFailed); err != nil {
|
||||
logger.Errorf("批量更新计划执行日志状态为失败失败: %v", err)
|
||||
// 这是一个非阻塞性错误,继续执行
|
||||
}
|
||||
// 直接调用新的方法来更新任务执行日志状态为取消
|
||||
if err := executionLogRepo.CancelAllIncompleteTaskExecutionLogs(); err != nil {
|
||||
logger.Errorf("更新所有未完成任务执行日志状态为取消失败: %v", err)
|
||||
// 这是一个非阻塞性错误,继续执行
|
||||
}
|
||||
|
||||
// 清空待执行列表
|
||||
|
||||
Reference in New Issue
Block a user