From 1f8b3b5e1b52fb769b4848d5047ded435d7a4b83 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 15 Dec 2023 10:03:05 +0100 Subject: [PATCH] Only update pipelineStatus in one place (#2952) --- pipeline/backend/types/config.go | 4 ++-- server/pipeline/create.go | 26 ++++++++++---------------- server/pipeline/pipelineStatus.go | 6 ++++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/pipeline/backend/types/config.go b/pipeline/backend/types/config.go index b1df35a43..0fe1e6fc0 100644 --- a/pipeline/backend/types/config.go +++ b/pipeline/backend/types/config.go @@ -14,9 +14,9 @@ package types -// Config defines the runtime configuration of a pipeline. +// Config defines the runtime configuration of a workflow. type Config struct { - Stages []*Stage `json:"pipeline"` // pipeline stages + Stages []*Stage `json:"pipeline"` // workflow stages Networks []*Network `json:"networks"` // network definitions Volumes []*Volume `json:"volumes"` // volume definitions Secrets []*Secret `json:"secrets"` // secret definitions diff --git a/server/pipeline/create.go b/server/pipeline/create.go index d440eccb5..64bd6f623 100644 --- a/server/pipeline/create.go +++ b/server/pipeline/create.go @@ -18,7 +18,6 @@ import ( "context" "fmt" "regexp" - "time" "github.com/rs/zerolog/log" @@ -128,16 +127,12 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline } func updatePipelineWithErr(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User, err error) error { - pipeline.Started = time.Now().Unix() - pipeline.Finished = pipeline.Started - pipeline.Status = model.StatusError - pipeline.Errors = errors.GetPipelineErrors(err) - dbErr := _store.UpdatePipeline(pipeline) - if dbErr != nil { - msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName) - log.Error().Err(dbErr).Msg(msg.Error()) - return msg + _pipeline, err := UpdateToStatusError(_store, *pipeline, err) + if err != nil { + return err } + // update value in ref + *pipeline = *_pipeline publishPipeline(ctx, pipeline, repo, repoUser) @@ -145,13 +140,12 @@ func updatePipelineWithErr(ctx context.Context, _store store.Store, pipeline *mo } func updatePipelinePending(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User) error { - pipeline.Status = model.StatusPending - dbErr := _store.UpdatePipeline(pipeline) - if dbErr != nil { - msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName) - log.Error().Err(dbErr).Msg(msg.Error()) - return msg + _pipeline, err := UpdateToStatusPending(_store, *pipeline, "") + if err != nil { + return err } + // update value in ref + *pipeline = *_pipeline publishPipeline(ctx, pipeline, repo, repoUser) diff --git a/server/pipeline/pipelineStatus.go b/server/pipeline/pipelineStatus.go index 2bf94423b..1081b4363 100644 --- a/server/pipeline/pipelineStatus.go +++ b/server/pipeline/pipelineStatus.go @@ -29,9 +29,11 @@ func UpdateToStatusRunning(store model.UpdatePipelineStore, pipeline model.Pipel } func UpdateToStatusPending(store model.UpdatePipelineStore, pipeline model.Pipeline, reviewer string) (*model.Pipeline, error) { - pipeline.Reviewer = reviewer + if reviewer != "" { + pipeline.Reviewer = reviewer + pipeline.Reviewed = time.Now().Unix() + } pipeline.Status = model.StatusPending - pipeline.Reviewed = time.Now().Unix() return &pipeline, store.UpdatePipeline(&pipeline) }