(ctx context.Context, taskRunUID int64, task *store.TaskMessage, executor Executor)
| 116 | } |
| 117 | |
| 118 | func (s *Scheduler) runTaskRunOnce(ctx context.Context, taskRunUID int64, task *store.TaskMessage, executor Executor) { |
| 119 | ctx = taskRunLogContext(ctx, task.ProjectID, taskRunUID) |
| 120 | |
| 121 | defer func() { |
| 122 | if r := recover(); r != nil { |
| 123 | err, ok := r.(error) |
| 124 | if !ok { |
| 125 | err = errors.Errorf("%v", r) |
| 126 | } |
| 127 | slog.ErrorContext(ctx, "Task scheduler V2 runTaskRunOnce PANIC RECOVER", log.BBError(err), log.BBStack("panic-stack")) |
| 128 | } |
| 129 | }() |
| 130 | taskRunRef := bus.TaskRunRef{ProjectID: task.ProjectID, ID: taskRunUID} |
| 131 | defer func() { |
| 132 | s.bus.RunningTaskRunsCancelFunc.Delete(taskRunRef) |
| 133 | }() |
| 134 | |
| 135 | driverCtx, cancel := context.WithCancel(ctx) |
| 136 | defer cancel() |
| 137 | s.bus.RunningTaskRunsCancelFunc.Store(taskRunRef, cancel) |
| 138 | |
| 139 | result, err := RunExecutorOnce(ctx, driverCtx, executor, task, taskRunUID) |
| 140 | |
| 141 | if err != nil && errors.Is(err, context.Canceled) { |
| 142 | slog.WarnContext(ctx, "task run is canceled", log.BBError(err)) |
| 143 | taskRunStatusPatch := &store.TaskRunStatusPatch{ |
| 144 | ID: taskRunUID, |
| 145 | ProjectID: task.ProjectID, |
| 146 | Updater: "", |
| 147 | Status: storepb.TaskRun_CANCELED, |
| 148 | AllowedStatuses: []storepb.TaskRun_Status{ |
| 149 | storepb.TaskRun_RUNNING, |
| 150 | }, |
| 151 | ResultProto: &storepb.TaskRunResult{}, |
| 152 | } |
| 153 | if _, err := s.store.UpdateTaskRunStatus(ctx, taskRunStatusPatch); err != nil { |
| 154 | if common.ErrorCode(err) == common.Conflict { |
| 155 | return |
| 156 | } |
| 157 | slog.ErrorContext(ctx, "Failed to mark task as CANCELED", log.BBError(err)) |
| 158 | return |
| 159 | } |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | if err != nil { |
| 164 | slog.WarnContext(ctx, "task run failed", log.BBError(err)) |
| 165 | taskRunStatusPatch := &store.TaskRunStatusPatch{ |
| 166 | ID: taskRunUID, |
| 167 | ProjectID: task.ProjectID, |
| 168 | Updater: "", |
| 169 | Status: storepb.TaskRun_FAILED, |
| 170 | AllowedStatuses: []storepb.TaskRun_Status{ |
| 171 | storepb.TaskRun_RUNNING, |
| 172 | }, |
| 173 | ResultProto: &storepb.TaskRunResult{ |
| 174 | Detail: err.Error(), |
| 175 | }, |
no test coverage detected