Skip to content

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

fix: create pending task runs race (#12559)

p0ny2effbc0ec3ae
diff --git a/backend/store/task_run.go b/backend/store/task_run.go
index 14d4d9f16a..a532eb8923 100644
--- a/backend/store/task_run.go
+++ b/backend/store/task_run.go
@@ -220,6 +220,11 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creates ...*TaskRunMe
}
defer tx.Rollback()
+ attempts, err := s.getTaskNextAttempt(ctx, tx, taskIDs)
+ if err != nil {
+ return errors.Wrapf(err, "failed to get task next attempt")
+ }
+
exist, err := s.checkTaskRunsExist(ctx, tx, taskIDs, []api.TaskRunStatus{api.TaskRunPending, api.TaskRunRunning, api.TaskRunDone})
if err != nil {
return errors.Wrapf(err, "failed to check if task runs exist")
@@ -228,11 +233,6 @@ func (s *Store) CreatePendingTaskRuns(ctx context.Context, creates ...*TaskRunMe
return errors.Errorf("cannot create pending task runs because there are pending/running/done task runs")
}
- attempts, err := s.getTaskNextAttempt(ctx, tx, taskIDs)
- if err != nil {
- return errors.Wrapf(err, "failed to get task next attempt")
- }
-
if err := s.createPendingTaskRunsTx(ctx, tx, attempts, creates); err != nil {
return errors.Wrapf(err, "failed to create pending task runs")
}