mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-18 04:15:15 +00:00
Only update pipelineStatus in one place (#2952)
This commit is contained in:
parent
ff1f51d6a9
commit
1f8b3b5e1b
3 changed files with 16 additions and 20 deletions
|
@ -14,9 +14,9 @@
|
||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
// Config defines the runtime configuration of a pipeline.
|
// Config defines the runtime configuration of a workflow.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Stages []*Stage `json:"pipeline"` // pipeline stages
|
Stages []*Stage `json:"pipeline"` // workflow stages
|
||||||
Networks []*Network `json:"networks"` // network definitions
|
Networks []*Network `json:"networks"` // network definitions
|
||||||
Volumes []*Volume `json:"volumes"` // volume definitions
|
Volumes []*Volume `json:"volumes"` // volume definitions
|
||||||
Secrets []*Secret `json:"secrets"` // secret definitions
|
Secrets []*Secret `json:"secrets"` // secret definitions
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"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 {
|
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, err := UpdateToStatusError(_store, *pipeline, err)
|
||||||
pipeline.Finished = pipeline.Started
|
if err != nil {
|
||||||
pipeline.Status = model.StatusError
|
return err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
// update value in ref
|
||||||
|
*pipeline = *_pipeline
|
||||||
|
|
||||||
publishPipeline(ctx, pipeline, repo, repoUser)
|
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 {
|
func updatePipelinePending(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User) error {
|
||||||
pipeline.Status = model.StatusPending
|
_pipeline, err := UpdateToStatusPending(_store, *pipeline, "")
|
||||||
dbErr := _store.UpdatePipeline(pipeline)
|
if err != nil {
|
||||||
if dbErr != nil {
|
return err
|
||||||
msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName)
|
|
||||||
log.Error().Err(dbErr).Msg(msg.Error())
|
|
||||||
return msg
|
|
||||||
}
|
}
|
||||||
|
// update value in ref
|
||||||
|
*pipeline = *_pipeline
|
||||||
|
|
||||||
publishPipeline(ctx, pipeline, repo, repoUser)
|
publishPipeline(ctx, pipeline, repo, repoUser)
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
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.Status = model.StatusPending
|
||||||
pipeline.Reviewed = time.Now().Unix()
|
|
||||||
return &pipeline, store.UpdatePipeline(&pipeline)
|
return &pipeline, store.UpdatePipeline(&pipeline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue