contacts agent to cancel build

This commit is contained in:
Brad Rydzewski 2015-04-30 00:42:23 -07:00
parent 3863617056
commit 543a46a755
2 changed files with 21 additions and 2 deletions

View file

@ -1,7 +1,10 @@
package server
import (
"fmt"
"io"
"net/http"
"net/url"
"strconv"
"time"
@ -239,5 +242,21 @@ 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
}
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)
}

View file

@ -3,8 +3,8 @@
<a href="/{{ repo.full_name }}">Back</a>
<div>
<button ng-if="build.state !== 'pending' && build.state !== 'started'" ng-click="restart()">Restart</button>
<button ng-if="build.state === 'pending' || build.state === 'started'" ng-click="cancel()">Cancel</button>
<button ng-if="build.state !== 'pending' && build.state !== 'running'" ng-click="restart()">Restart</button>
<button ng-if="build.state === 'pending' || build.state === 'running'" ng-click="cancel()">Cancel</button>
</div>
<dl>