From 4ea00f00356f245bc90dd83bfb37c95d220d562e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 8 Dec 2021 23:40:00 +0100 Subject: [PATCH] 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 --- cmd/agent/agent.go | 3 +++ cmd/server/server.go | 3 +++ server/api/build.go | 36 +++++++++++++++++++----------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cmd/agent/agent.go b/cmd/agent/agent.go index 790e01359..badcb6323 100644 --- a/cmd/agent/agent.go +++ b/cmd/agent/agent.go @@ -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") diff --git a/cmd/server/server.go b/cmd/server/server.go index 4dbe4c775..0b40d5f64 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -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") == "" { diff --git a/server/api/build.go b/server/api/build.go index 1d43ca593..b874c58fd 100644 --- a/server/api/build.go +++ b/server/api/build.go @@ -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 }