Merge pull request #2147 from bradrydzewski/master

ability to force kill zombie builds
This commit is contained in:
Brad Rydzewski 2017-08-01 14:22:37 -04:00 committed by GitHub
commit dba37018f4
4 changed files with 54 additions and 3 deletions

View file

@ -80,7 +80,7 @@ pipeline:
image: plugins/docker image: plugins/docker
repo: drone/drone repo: drone/drone
secrets: [ docker_username, docker_password ] secrets: [ docker_username, docker_password ]
tag: [ 0.8, 0.8.0 ] tag: [ 0.8, 0.8.0, 0.8.0-rc.3 ]
when: when:
event: tag event: tag
@ -89,7 +89,7 @@ pipeline:
repo: drone/agent repo: drone/agent
dockerfile: Dockerfile.agent dockerfile: Dockerfile.agent
secrets: [ docker_username, docker_password ] secrets: [ docker_username, docker_password ]
tag: [ 0.8, 0.8.0 ] tag: [ 0.8, 0.8.0, 0.8.0-rc.3 ]
when: when:
event: tag event: tag

View file

@ -106,6 +106,7 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
repo.POST("/repair", session.MustRepoAdmin(), server.RepairRepo) repo.POST("/repair", session.MustRepoAdmin(), server.RepairRepo)
repo.POST("/builds/:number", session.MustPush, server.PostBuild) repo.POST("/builds/:number", session.MustPush, server.PostBuild)
repo.DELETE("/builds/:number", session.MustAdmin(), server.ZombieKill)
repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval) repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval)
repo.POST("/builds/:number/decline", session.MustPush, server.PostDecline) repo.POST("/builds/:number/decline", session.MustPush, server.PostDecline)
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild) repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)

View file

@ -144,6 +144,56 @@ func DeleteBuild(c *gin.Context) {
c.String(204, "") c.String(204, "")
} }
// ZombieKill kills zombie processes stuck in an infinite pending
// or running state. This can only be invoked by administrators and
// may have negative effects.
func ZombieKill(c *gin.Context) {
repo := session.Repo(c)
// parse the build number and job sequence number from
// the repquest parameter.
num, _ := strconv.Atoi(c.Params.ByName("number"))
build, err := store.GetBuildNumber(c, repo, num)
if err != nil {
c.AbortWithError(404, err)
return
}
procs, err := store.FromContext(c).ProcList(build)
if err != nil {
c.AbortWithError(404, err)
return
}
if build.Status != model.StatusRunning {
c.String(400, "Cannot force cancel a non-running build")
return
}
for _, proc := range procs {
if proc.Running() {
proc.State = model.StatusKilled
proc.ExitCode = 137
proc.Stopped = time.Now().Unix()
if proc.Started == 0 {
proc.Started = proc.Stopped
}
}
}
for _, proc := range procs {
store.FromContext(c).ProcUpdate(proc)
Config.Services.Queue.Error(context.Background(), fmt.Sprint(proc.ID), queue.ErrCancel)
}
build.Status = model.StatusKilled
build.Finished = time.Now().Unix()
store.FromContext(c).UpdateBuild(build)
c.String(204, "")
}
func PostApproval(c *gin.Context) { func PostApproval(c *gin.Context) {
var ( var (
remote_ = remote.FromContext(c) remote_ = remote.FromContext(c)

View file

@ -10,7 +10,7 @@ var (
// VersionPatch is for backwards-compatible bug fixes // VersionPatch is for backwards-compatible bug fixes
VersionPatch int64 = 0 VersionPatch int64 = 0
// VersionPre indicates prerelease // VersionPre indicates prerelease
VersionPre string VersionPre string = "rc.3"
// VersionDev indicates development branch. Releases will be empty string. // VersionDev indicates development branch. Releases will be empty string.
VersionDev string VersionDev string
) )