hooked up restart, cancel in user interface

This commit is contained in:
Brad Rydzewski 2015-04-28 16:27:30 -07:00
parent 864a47f502
commit 7649248385
2 changed files with 39 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package server
import (
"io"
"strconv"
"time"
"github.com/drone/drone/common"
"github.com/drone/drone/parser/inject"
@ -190,6 +191,7 @@ func RunBuild(c *gin.Context) {
// DELETE /api/builds/:owner/:name/builds/:number
//
func KillBuild(c *gin.Context) {
queue := ToQueue(c)
store := ToDatastore(c)
repo := ToRepo(c)
num, err := strconv.Atoi(c.Params.ByName("number"))
@ -209,7 +211,33 @@ func KillBuild(c *gin.Context) {
return
}
// TODO tell queue to cancel build
// remove from the queue if exists
for _, item := range queue.Items() {
if item.Repo.FullName == repo.FullName && item.Build.Number == build.Number {
queue.Remove(item)
break
}
}
c.Writer.WriteHeader(202)
build.State = common.StateKilled
build.Finished = time.Now().Unix()
if build.Started == 0 {
build.Started = build.Finished
}
build.Duration = build.Finished - build.Started
for _, task := range build.Tasks {
if task.State != common.StatePending && task.State != common.StateRunning {
continue
}
task.State = common.StateKilled
task.Started = build.Started
task.Finished = build.Finished
}
err = store.SetBuild(repo.FullName, build)
if err != nil {
c.Fail(500, err)
return
}
c.JSON(200, build)
}

View file

@ -120,13 +120,19 @@
});
$scope.restart = function() {
builds.restart(fullName, number).catch(function(err){
builds.restart(fullName, number).then(function(payload){
$scope.build = payload.data;
$scope.task = payload.data.tasks[step-1];
}).catch(function(err){
$scope.error = err;
});
};
$scope.cancel = function() {
builds.cancel(fullName, number).catch(function(err) {
builds.cancel(fullName, number).then(function(payload){
$scope.build = payload.data;
$scope.task = payload.data.tasks[step-1];
}).catch(function(err) {
$scope.error = err;
});
};