@@ -27,7 +27,6 @@ import (
2727	"code.gitea.io/gitea/modules/log" 
2828	"code.gitea.io/gitea/modules/storage" 
2929	"code.gitea.io/gitea/modules/templates" 
30- 	"code.gitea.io/gitea/modules/timeutil" 
3130	"code.gitea.io/gitea/modules/util" 
3231	"code.gitea.io/gitea/modules/web" 
3332	"code.gitea.io/gitea/routers/common" 
@@ -572,45 +571,19 @@ func Cancel(ctx *context_module.Context) {
572571	var  updatedjobs  []* actions_model.ActionRunJob 
573572
574573	if  err  :=  db .WithTx (ctx , func (ctx  context.Context ) error  {
575- 		for  _ , job  :=  range  jobs  {
576- 			status  :=  job .Status 
577- 			if  status .IsDone () {
578- 				continue 
579- 			}
580- 			if  job .TaskID  ==  0  {
581- 				job .Status  =  actions_model .StatusCancelled 
582- 				job .Stopped  =  timeutil .TimeStampNow ()
583- 				n , err  :=  actions_model .UpdateRunJob (ctx , job , builder.Eq {"task_id" : 0 }, "status" , "stopped" )
584- 				if  err  !=  nil  {
585- 					return  err 
586- 				}
587- 				if  n  ==  0  {
588- 					return  errors .New ("job has changed, try again" )
589- 				}
590- 				if  n  >  0  {
591- 					updatedjobs  =  append (updatedjobs , job )
592- 				}
593- 				continue 
594- 			}
595- 			if  err  :=  actions_model .StopTask (ctx , job .TaskID , actions_model .StatusCancelled ); err  !=  nil  {
596- 				return  err 
597- 			}
574+ 		cancelledJobs , err  :=  actions_model .CancelJobs (ctx , jobs )
575+ 		if  err  !=  nil  {
576+ 			return  fmt .Errorf ("cancel jobs: %w" , err )
598577		}
578+ 		updatedjobs  =  append (updatedjobs , cancelledJobs ... )
599579		return  nil 
600580	}); err  !=  nil  {
601581		ctx .ServerError ("StopTask" , err )
602582		return 
603583	}
604584
605585	actions_service .CreateCommitStatus (ctx , jobs ... )
606- 
607- 	run , err  :=  actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
608- 	if  err  !=  nil  {
609- 		ctx .ServerError ("GetRunByIndex" , err )
610- 	}
611- 	if  err  :=  actions_service .EmitJobsIfReady (run .ID ); err  !=  nil  {
612- 		log .Error ("Emit ready jobs of run %d: %v" , run .ID , err )
613- 	}
586+ 	actions_service .EmitJobsIfReadyByJobs (updatedjobs )
614587
615588	for  _ , job  :=  range  updatedjobs  {
616589		_  =  job .LoadAttributes (ctx )
0 commit comments