initial work on build cancellation
This commit is contained in:
parent
f82c8ff6d7
commit
0034c12141
2 changed files with 19 additions and 18 deletions
2
drone.go
2
drone.go
|
@ -53,6 +53,7 @@ func main() {
|
|||
api.Use(server.SetSettings(settings))
|
||||
api.Use(server.SetSession(session))
|
||||
api.Use(server.SetUser(session))
|
||||
api.Use(server.SetRunner(&runner_))
|
||||
|
||||
user := api.Group("/user")
|
||||
{
|
||||
|
@ -141,7 +142,6 @@ func main() {
|
|||
{
|
||||
stream.Use(server.SetRepo())
|
||||
stream.Use(server.SetPerm())
|
||||
stream.Use(server.SetRunner(&runner_))
|
||||
stream.GET("/:owner/:name", server.GetRepoEvents)
|
||||
stream.GET("/:owner/:name/:build/:number", server.GetStream)
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -194,6 +191,7 @@ func RunBuild(c *gin.Context) {
|
|||
// DELETE /api/builds/:owner/:name/builds/:number
|
||||
//
|
||||
func KillBuild(c *gin.Context) {
|
||||
runner := ToRunner(c)
|
||||
queue := ToQueue(c)
|
||||
store := ToDatastore(c)
|
||||
repo := ToRepo(c)
|
||||
|
@ -242,21 +240,24 @@ func KillBuild(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// get the agent from the repository so we can
|
||||
// notify the agent to kill the build.
|
||||
agent, err := store.BuildAgent(repo.FullName, build.Number)
|
||||
if err != nil {
|
||||
c.JSON(200, build)
|
||||
return
|
||||
for _, task := range build.Tasks {
|
||||
runner.Cancel(repo.FullName, build.Number, task.Number)
|
||||
}
|
||||
url_, _ := url.Parse("http://" + agent.Addr)
|
||||
url_.Path = fmt.Sprintf("/cancel/%s/%v", repo.FullName, build.Number)
|
||||
resp, err := http.Post(url_.String(), "application/json", nil)
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
// // get the agent from the repository so we can
|
||||
// // notify the agent to kill the build.
|
||||
// agent, err := store.BuildAgent(repo.FullName, build.Number)
|
||||
// if err != nil {
|
||||
// c.JSON(200, build)
|
||||
// return
|
||||
// }
|
||||
// url_, _ := url.Parse("http://" + agent.Addr)
|
||||
// url_.Path = fmt.Sprintf("/cancel/%s/%v", repo.FullName, build.Number)
|
||||
// resp, err := http.Post(url_.String(), "application/json", nil)
|
||||
// if err != nil {
|
||||
// c.Fail(500, err)
|
||||
// return
|
||||
// }
|
||||
// defer resp.Body.Close()
|
||||
|
||||
c.JSON(200, build)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue