From 7649248385dff95b7e79430947beae715a3394df Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 28 Apr 2015 16:27:30 -0700 Subject: [PATCH] hooked up restart, cancel in user interface --- server/builds.go | 32 +++++++++++++++++++-- server/static/scripts/controllers/builds.js | 12 ++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/server/builds.go b/server/builds.go index 052af5802..2f89bacb7 100644 --- a/server/builds.go +++ b/server/builds.go @@ -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) } diff --git a/server/static/scripts/controllers/builds.js b/server/static/scripts/controllers/builds.js index 248a490ad..0620696a0 100644 --- a/server/static/scripts/controllers/builds.js +++ b/server/static/scripts/controllers/builds.js @@ -48,7 +48,7 @@ // update repository $scope.repo = event.repo; $scope.$apply(); - + var added = false; for (var i=0;i<$scope.builds.length;i++) { var build = $scope.builds[i]; @@ -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; }); };