diff options
author | Jason Song <i@wolfogre.com> | 2023-05-10 19:54:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-10 13:54:18 +0200 |
commit | 2d0ff00823bf92ee32df107416fd30010638f21d (patch) | |
tree | a7cc8e322cc1f4be970150fd910298d4609f2d34 /models/actions | |
parent | ea7954f069bf8bcb87d520f8aab0a80b0768590d (diff) | |
download | gitea-2d0ff00823bf92ee32df107416fd30010638f21d.tar.gz gitea-2d0ff00823bf92ee32df107416fd30010638f21d.zip |
Improve updating Actions tasks (#24600)
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'models/actions')
-rw-r--r-- | models/actions/task.go | 17 |
1 files changed, 11 insertions, 6 deletions
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 } |