Make cancel pipeline work again (#585)

* logger: on level debug or trace add caller to logs

* more logging

* fix cancel bug

* ignore error if occur for queue cancel
This commit is contained in:
6543 2021-12-08 23:40:00 +01:00 committed by GitHub
parent 3ec00140d9
commit 4ea00f0035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 17 deletions

View file

@ -64,6 +64,9 @@ func loop(c *cli.Context) error {
}
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
log.Logger = log.With().Caller().Logger()
}
if c.IsSet("log-level") {
logLevelFlag := c.String("log-level")

View file

@ -74,6 +74,9 @@ func run(c *cli.Context) error {
}
zerolog.SetGlobalLevel(lvl)
}
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
log.Logger = log.With().Caller().Logger()
}
log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
if c.String("server-host") == "" {

View file

@ -153,19 +153,19 @@ func GetProcLogs(c *gin.Context) {
build, err := _store.GetBuildNumber(repo, num)
if err != nil {
_ = c.AbortWithError(404, err)
_ = c.AbortWithError(http.StatusNotFound, err)
return
}
proc, err := _store.ProcFind(build, pid)
if err != nil {
_ = c.AbortWithError(404, err)
_ = c.AbortWithError(http.StatusNotFound, err)
return
}
rc, err := _store.LogFind(proc)
if err != nil {
_ = c.AbortWithError(404, err)
_ = c.AbortWithError(http.StatusNotFound, err)
return
}
@ -185,18 +185,18 @@ func DeleteBuild(c *gin.Context) {
build, err := _store.GetBuildNumber(repo, num)
if err != nil {
_ = c.AbortWithError(404, err)
_ = c.AbortWithError(http.StatusNotFound, err)
return
}
procs, err := _store.ProcList(build)
if err != nil {
_ = c.AbortWithError(404, err)
_ = c.AbortWithError(http.StatusNotFound, err)
return
}
if build.Status != model.StatusRunning && build.Status != model.StatusPending {
c.String(400, "Cannot cancel a non-running or non-pending build")
c.String(http.StatusBadRequest, "Cannot cancel a non-running or non-pending build")
return
}
@ -217,17 +217,18 @@ func DeleteBuild(c *gin.Context) {
}
}
if err := server.Config.Services.Queue.EvictAtOnce(c, procToEvict); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
if len(procToEvict) != 0 {
if err := server.Config.Services.Queue.EvictAtOnce(c, procToEvict); err != nil {
log.Error().Err(err).Msgf("queue: evict_at_once: %v", procToEvict)
}
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToEvict, queue.ErrCancel); err != nil {
log.Error().Err(err).Msgf("queue: evict_at_once: %v", procToEvict)
}
}
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToEvict, queue.ErrCancel); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToCancel, queue.ErrCancel); err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
if len(procToCancel) != 0 {
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToCancel, queue.ErrCancel); err != nil {
log.Error().Err(err).Msgf("queue: evict_at_once: %v", procToCancel)
}
}
// Then update the DB status for pending builds
@ -248,7 +249,8 @@ func DeleteBuild(c *gin.Context) {
killedBuild, err := shared.UpdateToStatusKilled(_store, *build)
if err != nil {
_ = c.AbortWithError(500, err)
log.Error().Err(err).Msgf("UpdateToStatusKilled: %v", build)
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
}