Auto cancel blocked pipelines (#905)

This commit is contained in:
Anbraten 2022-05-11 07:45:21 +02:00 committed by GitHub
parent 7313de2b1d
commit bdb007e064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

View file

@ -295,19 +295,15 @@ func cancelBuild(
return http.StatusInternalServerError, err
}
// For pending builds, we stream the UI the latest state.
// For running builds, the UI will be updated when the agents acknowledge the cancel
if build.Status == model.StatusPending {
procs, err = _store.ProcList(killedBuild)
if err != nil {
return http.StatusNotFound, err
}
if killedBuild.Procs, err = model.Tree(procs); err != nil {
return http.StatusInternalServerError, err
}
if err := publishToTopic(ctx, killedBuild, repo); err != nil {
log.Error().Err(err).Msg("publishToTopic")
}
procs, err = _store.ProcList(killedBuild)
if err != nil {
return http.StatusNotFound, err
}
if killedBuild.Procs, err = model.Tree(procs); err != nil {
return http.StatusInternalServerError, err
}
if err := publishToTopic(ctx, killedBuild, repo); err != nil {
log.Error().Err(err).Msg("publishToTopic")
}
return http.StatusNoContent, nil

View file

@ -80,11 +80,12 @@ func (s storage) GetBuildList(repo *model.Repo, page int) ([]*model.Build, error
Find(&builds)
}
// GetActiveBuildList get all builds that are pending, running or blocked
func (s storage) GetActiveBuildList(repo *model.Repo, page int) ([]*model.Build, error) {
builds := make([]*model.Build, 0, perPage)
query := s.engine.
Where("build_repo_id = ?", repo.ID).
Where("build_status = ? or build_status = ?", "pending", "running").
In("build_status", model.StatusPending, model.StatusRunning, model.StatusBlocked).
Desc("build_number")
if page > 0 {
query = query.Limit(perPage, perPage*(page-1))