@@ -291,7 +291,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
291291 }
292292
293293 task .LogFilename = logFileName (job .Run .Repo .FullName (), task .ID )
294- if _ , err := e . ID ( task . ID ). Cols ( "log_filename" ). Update ( task ); err != nil {
294+ if err := UpdateTask ( ctx , task , "log_filename" ); err != nil {
295295 return nil , false , err
296296 }
297297
@@ -367,9 +367,18 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT
367367 return nil , util .ErrNotExist
368368 }
369369
370+ if task .Status .IsDone () {
371+ // the state is final, do nothing
372+ return task , nil
373+ }
374+
375+ // state.Result is not unspecified means the task is finished
370376 if state .Result != runnerv1 .Result_RESULT_UNSPECIFIED {
371377 task .Status = Status (state .Result )
372378 task .Stopped = timeutil .TimeStamp (state .StoppedAt .AsTime ().Unix ())
379+ if err := UpdateTask (ctx , task , "status" , "stopped" ); err != nil {
380+ return nil , err
381+ }
373382 if _ , err := UpdateRunJob (ctx , & ActionRunJob {
374383 ID : task .JobID ,
375384 Status : task .Status ,
@@ -379,10 +388,6 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT
379388 }
380389 }
381390
382- if _ , err := e .ID (task .ID ).Update (task ); err != nil {
383- return nil , err
384- }
385-
386391 if err := task .LoadAttributes (ctx ); err != nil {
387392 return nil , err
388393 }
@@ -440,7 +445,7 @@ func StopTask(ctx context.Context, taskID int64, status Status) error {
440445 return err
441446 }
442447
443- if _ , err := e . ID ( task . ID ). Update ( task ); err != nil {
448+ if err := UpdateTask ( ctx , task , "status" , "stopped" ); err != nil {
444449 return err
445450 }
446451
0 commit comments