Skip to content

Commit e68da9a

Browse files
committed
prevent increment task.ID in idle
1 parent 4a5bd75 commit e68da9a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

models/actions/task.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
233233
if err := task.GenerateToken(); err != nil {
234234
return nil, false, err
235235
}
236-
237-
if _, err := e.Insert(task); err != nil {
238-
return nil, false, err
239-
}
236+
// Insert the task on demand if task.ID == 0, if at least one job matches avoid unnecessary id increment
240237

241238
jobCond := builder.NewCond()
242239
if runner.RepoID != 0 {
@@ -269,6 +266,12 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
269266

270267
for _, v := range jobs {
271268
if runner.CanMatchLabels(v.RunsOn) {
269+
// Insert on demand, auto removed by aborted transaction if no job matches
270+
if task.ID == 0 {
271+
if _, err := e.Insert(task); err != nil {
272+
return nil, false, err
273+
}
274+
}
272275
// Reserve our job before preparing task, otherwise continue searching
273276
v.TaskID = task.ID
274277
if n, err := UpdateRunJob(ctx, v, builder.Eq{"task_id": 0}, "task_id"); err != nil {

0 commit comments

Comments
 (0)