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