@@ -238,7 +238,7 @@ func ShouldBlockJobByConcurrency(ctx context.Context, job *ActionRunJob) (bool,
238238 return ShouldBlockRunByConcurrency (ctx , job .Run )
239239}
240240
241- func CancelPreviousJobsByConcurrency (ctx context.Context , job * ActionRunJob ) ([]* ActionRunJob , error ) {
241+ func CancelPreviousJobsByJobConcurrency (ctx context.Context , job * ActionRunJob ) ([]* ActionRunJob , error ) {
242242 var cancelledJobs []* ActionRunJob
243243
244244 if job .RawConcurrencyGroup != "" {
@@ -270,33 +270,12 @@ func CancelPreviousJobsByConcurrency(ctx context.Context, job *ActionRunJob) ([]
270270 if err := job .LoadRun (ctx ); err != nil {
271271 return cancelledJobs , fmt .Errorf ("load run: %w" , err )
272272 }
273- if job .Run .ConcurrencyGroup != "" && job .Run .ConcurrencyCancel {
274- // cancel previous runs in the same concurrency group
275- runs , err := db .Find [ActionRun ](ctx , & FindRunOptions {
276- RepoID : job .RepoID ,
277- ConcurrencyGroup : job .Run .ConcurrencyGroup ,
278- Status : []Status {StatusRunning , StatusWaiting , StatusBlocked },
279- })
280- if err != nil {
281- return cancelledJobs , fmt .Errorf ("find runs: %w" , err )
282- }
283- for _ , run := range runs {
284- if run .ID == job .Run .ID {
285- continue
286- }
287- jobs , err := db .Find [ActionRunJob ](ctx , FindRunJobOptions {
288- RunID : run .ID ,
289- })
290- if err != nil {
291- return cancelledJobs , fmt .Errorf ("find run %d jobs: %w" , run .ID , err )
292- }
293- cjs , err := CancelJobs (ctx , jobs )
294- if err != nil {
295- return cancelledJobs , fmt .Errorf ("cancel run %d jobs: %w" , run .ID , err )
296- }
297- cancelledJobs = append (cancelledJobs , cjs ... )
298- }
273+
274+ cancelledJobsByRun , err := CancelPreviousJobsByRunConcurrency (ctx , job .Run )
275+ if err != nil {
276+ return cancelledJobs , fmt .Errorf ("cancel runs: %w" , err )
299277 }
278+ cancelledJobs = append (cancelledJobs , cancelledJobsByRun ... )
300279
301280 return cancelledJobs , nil
302281}
0 commit comments