@@ -106,7 +106,7 @@ func CancelAbandonedJobs(ctx context.Context) error {
106106		UpdatedBefore : timeutil .TimeStamp (time .Now ().Add (- setting .Actions .AbandonedJobTimeout ).Unix ()),
107107	})
108108	if  err  !=  nil  {
109- 		log .Error ( "CancelAbandonedJobs : %v" , err )
109+ 		log .Warn ( "find abandoned tasks : %v" , err )
110110		return  err 
111111	}
112112
@@ -124,7 +124,7 @@ func CancelAbandonedJobs(ctx context.Context) error {
124124			updated  =  err  ==  nil  &&  n  >  0 
125125			return  err 
126126		}); err  !=  nil  {
127- 			log .Warn ("CancelAbandonedJobs jobid  %v: %v" , job .ID , err )
127+ 			log .Warn ("cancel abandoned job  %v: %v" , job .ID , err )
128128			// go on 
129129		}
130130		CreateCommitStatus (ctx , job )
@@ -134,24 +134,18 @@ func CancelAbandonedJobs(ctx context.Context) error {
134134		}
135135	}
136136
137- 	for  _ , obj  :=  range  updatedRuns  {
138- 		jobs , err  :=  actions_model .GetRunJobsByRunID (ctx , obj .RunID )
137+ 	for  _ , job  :=  range  updatedRuns  {
138+ 		c , err  :=  db .Count [actions_model.ActionRunJob ](ctx , actions_model.FindRunJobOptions {
139+ 			RunID :    job .RunID ,
140+ 			Statuses : []actions_model.Status {actions_model .StatusWaiting , actions_model .StatusBlocked , actions_model .StatusRunning },
141+ 		})
139142		if  err  !=  nil  {
140- 			log .Error ("CancelAbandonedJobs runid  %d: %v" , obj .RunID , err )
143+ 			log .Error ("Count waiting jobs for run  %d: %v" , job .RunID , err )
141144			continue 
142145		}
143- 
144- 		unfinished  :=  false 
145- 		for  _ , job  :=  range  jobs  {
146- 			if  ! job .Status .IsDone () {
147- 				unfinished  =  true 
148- 				break 
149- 			}
150- 		}
151- 		if  unfinished  {
152- 			continue 
146+ 		if  c  ==  0  {
147+ 			NotifyWorkflowRunStatusUpdateWithReload (ctx , job )
153148		}
154- 		NotifyWorkflowRunStatusUpdateWithReload (ctx , obj )
155149	}
156150
157151	return  nil 
0 commit comments