Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: handle scheduler states revertings (#17040)

p0ny7ffa2b727a35
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index 9b3d1467d5..962a2562c0 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -502,18 +502,20 @@ func (s *SchedulerV2) scheduleRunningTaskRun(ctx context.Context, taskRun *store
}
}()
- s.stateCfg.TaskRunSchedulerInfo.Delete(taskRun.ID)
+ // Set taskrun StartAt when it's about to run.
+ // So that the waiting time is not taken into account of the actual execution time.
+ if err := s.store.UpdateTaskRunStartAt(ctx, taskRun.ID); err != nil {
+ return errors.Wrapf(err, "failed to update task run start at")
+ }
+ // We MUST NOT return early below this line.
+ // If we do want to return early, we must revert related states.
+ s.stateCfg.TaskRunSchedulerInfo.Delete(taskRun.ID)
s.stateCfg.RunningTaskRuns.Store(taskRun.ID, true)
if task.DatabaseName != nil {
s.stateCfg.RunningDatabaseMigration.Store(getDatabaseKey(task.InstanceID, *task.DatabaseName), task.ID)
}
- // Set taskrun StartAt when it's about to run.
- // So that the waiting time is not taken into account of the actual execution time.
- if err := s.store.UpdateTaskRunStartAt(ctx, taskRun.ID); err != nil {
- return errors.Wrapf(err, "failed to update task run start at")
- }
s.store.CreateTaskRunLogS(ctx, taskRun.ID, time.Now(), s.profile.DeployID, &storepb.TaskRunLog{
Type: storepb.TaskRunLog_TASK_RUN_STATUS_UPDATE,
TaskRunStatusUpdate: &storepb.TaskRunLog_TaskRunStatusUpdate{