From 2d0ff00823bf92ee32df107416fd30010638f21d Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 10 May 2023 19:54:18 +0800 Subject: Improve updating Actions tasks (#24600) Co-authored-by: Giteabot --- models/actions/task.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'models/actions') diff --git a/models/actions/task.go b/models/actions/task.go index ffec4c92aa..66cd2bbea1 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -291,7 +291,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask } task.LogFilename = logFileName(job.Run.Repo.FullName(), task.ID) - if _, err := e.ID(task.ID).Cols("log_filename").Update(task); err != nil { + if err := UpdateTask(ctx, task, "log_filename"); err != nil { return nil, false, err } @@ -367,9 +367,18 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT return nil, util.ErrNotExist } + if task.Status.IsDone() { + // the state is final, do nothing + return task, nil + } + + // state.Result is not unspecified means the task is finished if state.Result != runnerv1.Result_RESULT_UNSPECIFIED { task.Status = Status(state.Result) task.Stopped = timeutil.TimeStamp(state.StoppedAt.AsTime().Unix()) + if err := UpdateTask(ctx, task, "status", "stopped"); err != nil { + return nil, err + } if _, err := UpdateRunJob(ctx, &ActionRunJob{ ID: task.JobID, Status: task.Status, @@ -379,10 +388,6 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT } } - if _, err := e.ID(task.ID).Update(task); err != nil { - return nil, err - } - if err := task.LoadAttributes(ctx); err != nil { return nil, err } @@ -440,7 +445,7 @@ func StopTask(ctx context.Context, taskID int64, status Status) error { return err } - if _, err := e.ID(task.ID).Update(task); err != nil { + if err := UpdateTask(ctx, task, "status", "stopped"); err != nil { return err } -- cgit v1.2.3