mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 00:46:30 +00:00
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:
parent
3ec00140d9
commit
4ea00f0035
3 changed files with 25 additions and 17 deletions
|
@ -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")
|
||||
|
|
|
@ -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") == "" {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue