mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-09 17:15:31 +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)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
}
|
}
|
||||||
|
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
|
||||||
|
log.Logger = log.With().Caller().Logger()
|
||||||
|
}
|
||||||
|
|
||||||
if c.IsSet("log-level") {
|
if c.IsSet("log-level") {
|
||||||
logLevelFlag := c.String("log-level")
|
logLevelFlag := c.String("log-level")
|
||||||
|
|
|
@ -74,6 +74,9 @@ func run(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
zerolog.SetGlobalLevel(lvl)
|
zerolog.SetGlobalLevel(lvl)
|
||||||
}
|
}
|
||||||
|
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
|
||||||
|
log.Logger = log.With().Caller().Logger()
|
||||||
|
}
|
||||||
log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
|
log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
|
||||||
|
|
||||||
if c.String("server-host") == "" {
|
if c.String("server-host") == "" {
|
||||||
|
|
|
@ -153,19 +153,19 @@ func GetProcLogs(c *gin.Context) {
|
||||||
|
|
||||||
build, err := _store.GetBuildNumber(repo, num)
|
build, err := _store.GetBuildNumber(repo, num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(404, err)
|
_ = c.AbortWithError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
proc, err := _store.ProcFind(build, pid)
|
proc, err := _store.ProcFind(build, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(404, err)
|
_ = c.AbortWithError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rc, err := _store.LogFind(proc)
|
rc, err := _store.LogFind(proc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(404, err)
|
_ = c.AbortWithError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,18 +185,18 @@ func DeleteBuild(c *gin.Context) {
|
||||||
|
|
||||||
build, err := _store.GetBuildNumber(repo, num)
|
build, err := _store.GetBuildNumber(repo, num)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(404, err)
|
_ = c.AbortWithError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
procs, err := _store.ProcList(build)
|
procs, err := _store.ProcList(build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(404, err)
|
_ = c.AbortWithError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Status != model.StatusRunning && build.Status != model.StatusPending {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,17 +217,18 @@ func DeleteBuild(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(procToEvict) != 0 {
|
||||||
if err := server.Config.Services.Queue.EvictAtOnce(c, procToEvict); err != nil {
|
if err := server.Config.Services.Queue.EvictAtOnce(c, procToEvict); err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
log.Error().Err(err).Msgf("queue: evict_at_once: %v", procToEvict)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToEvict, queue.ErrCancel); err != nil {
|
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToEvict, queue.ErrCancel); err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
log.Error().Err(err).Msgf("queue: evict_at_once: %v", procToEvict)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if len(procToCancel) != 0 {
|
||||||
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToCancel, queue.ErrCancel); err != nil {
|
if err := server.Config.Services.Queue.ErrorAtOnce(c, procToCancel, queue.ErrCancel); err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
log.Error().Err(err).Msgf("queue: evict_at_once: %v", procToCancel)
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then update the DB status for pending builds
|
// Then update the DB status for pending builds
|
||||||
|
@ -248,7 +249,8 @@ func DeleteBuild(c *gin.Context) {
|
||||||
|
|
||||||
killedBuild, err := shared.UpdateToStatusKilled(_store, *build)
|
killedBuild, err := shared.UpdateToStatusKilled(_store, *build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.AbortWithError(500, err)
|
log.Error().Err(err).Msgf("UpdateToStatusKilled: %v", build)
|
||||||
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue