mirror of
https://github.com/harness/drone.git
synced 2025-05-05 04:49:32 +08:00
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package manager
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/harness/gitness/internal/pipeline/events"
|
|
"github.com/harness/gitness/internal/store"
|
|
"github.com/harness/gitness/types"
|
|
"github.com/harness/gitness/types/enum"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type updater struct {
|
|
Executions store.ExecutionStore
|
|
Repos store.RepoStore
|
|
Events events.EventsStreamer
|
|
Steps store.StepStore
|
|
Stages store.StageStore
|
|
}
|
|
|
|
func (u *updater) do(ctx context.Context, step *types.Step) error {
|
|
log := log.With().
|
|
Str("step.name", step.Name).
|
|
Str("step.status", step.Status).
|
|
Int64("step.id", step.ID).
|
|
Logger()
|
|
|
|
if len(step.Error) > 500 {
|
|
step.Error = step.Error[:500]
|
|
}
|
|
err := u.Steps.Update(noContext, step)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("manager: cannot update step")
|
|
return err
|
|
}
|
|
|
|
stage, err := u.Stages.Find(noContext, step.StageID)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("manager: cannot find stage")
|
|
return nil
|
|
}
|
|
|
|
execution, err := u.Executions.Find(noContext, stage.ExecutionID)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("manager: cannot find execution")
|
|
return nil
|
|
}
|
|
|
|
repo, err := u.Repos.Find(noContext, execution.RepoID)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("manager: cannot find repo")
|
|
return nil
|
|
}
|
|
|
|
stages, err := u.Stages.ListWithSteps(noContext, stage.ExecutionID)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("manager: cannot find stages")
|
|
return nil
|
|
}
|
|
|
|
execution.Stages = stages
|
|
err = u.Events.Publish(noContext, repo.ParentID, executionEvent(enum.ExecutionUpdated, execution))
|
|
if err != nil {
|
|
log.Warn().Err(err).Msg("manager: cannot publish execution updated event")
|
|
}
|
|
|
|
return nil
|
|
}
|