From bdb007e064a9ed2872b5a78623b1f4b83acb798f Mon Sep 17 00:00:00 2001 From: Anbraten Date: Wed, 11 May 2022 07:45:21 +0200 Subject: [PATCH] Auto cancel blocked pipelines (#905) --- server/api/build.go | 22 +++++++++------------- server/store/datastore/build.go | 3 ++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/server/api/build.go b/server/api/build.go index ae4fbef60..2f2037185 100644 --- a/server/api/build.go +++ b/server/api/build.go @@ -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 diff --git a/server/store/datastore/build.go b/server/store/datastore/build.go index accb2ffd3..979b34c10 100644 --- a/server/store/datastore/build.go +++ b/server/store/datastore/build.go @@ -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))