ability to cancel a single job (not entire build)
This commit is contained in:
parent
37e515fbca
commit
6bc28bd41c
5 changed files with 47 additions and 4 deletions
|
@ -93,7 +93,32 @@ func GetBuildLogs(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteBuild(c *gin.Context) {
|
func DeleteBuild(c *gin.Context) {
|
||||||
c.String(http.StatusOK, "DeleteBuild")
|
engine_ := context.Engine(c)
|
||||||
|
repo := session.Repo(c)
|
||||||
|
db := context.Database(c)
|
||||||
|
|
||||||
|
// parse the build number and job sequence number from
|
||||||
|
// the repquest parameter.
|
||||||
|
num, _ := strconv.Atoi(c.Params.ByName("number"))
|
||||||
|
seq, _ := strconv.Atoi(c.Params.ByName("job"))
|
||||||
|
|
||||||
|
build, err := model.GetBuildNumber(db, repo, num)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
job, err := model.GetJobNumber(db, build, seq)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
node, err := model.GetNode(db, job.NodeID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
engine_.Cancel(build.ID, job.ID, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostBuild(c *gin.Context) {
|
func PostBuild(c *gin.Context) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ func Load(db *sql.DB, remote remote.Remote) Engine {
|
||||||
|
|
||||||
// Cancel cancels the job running on the specified Node.
|
// Cancel cancels the job running on the specified Node.
|
||||||
func (e *engine) Cancel(build, job int64, node *model.Node) error {
|
func (e *engine) Cancel(build, job int64, node *model.Node) error {
|
||||||
client, err := dockerclient.NewDockerClient(node.Addr, nil)
|
client, err := newDockerClient(node.Addr, node.Cert, node.Key, node.CA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
||||||
repo.DELETE("", session.MustPush, controller.DeleteRepo)
|
repo.DELETE("", session.MustPush, controller.DeleteRepo)
|
||||||
|
|
||||||
repo.POST("/builds/:number", session.MustPush, controller.PostBuild)
|
repo.POST("/builds/:number", session.MustPush, controller.PostBuild)
|
||||||
// repo.DELETE("/builds/:number", MustPush(), controller.DeleteBuild)
|
repo.DELETE("/builds/:number/:job", session.MustPush, controller.DeleteBuild)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ function JobViewModel(repo, build, job, status) {
|
||||||
|
|
||||||
self.stream = function() {
|
self.stream = function() {
|
||||||
$( "#output" ).html("");
|
$( "#output" ).html("");
|
||||||
|
$("#restart").hide();
|
||||||
|
$("#cancel").show();
|
||||||
|
|
||||||
var buf = new Drone.Buffer();
|
var buf = new Drone.Buffer();
|
||||||
buf.start(document.getElementById("output"));
|
buf.start(document.getElementById("output"));
|
||||||
|
@ -32,6 +34,7 @@ function JobViewModel(repo, build, job, status) {
|
||||||
|
|
||||||
if (status !== "running" && status !== "pending") {
|
if (status !== "running" && status !== "pending") {
|
||||||
Logs(repo, build, job);
|
Logs(repo, build, job);
|
||||||
|
$("#restart").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status === "running") {
|
if (status === "running") {
|
||||||
|
@ -53,6 +56,19 @@ function JobViewModel(repo, build, job, status) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#cancel").click(function() {
|
||||||
|
$("#cancel").hide();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/api/repos/"+repo+"/builds/"+build+"/"+job,
|
||||||
|
type: "DELETE",
|
||||||
|
success: function( data ) { },
|
||||||
|
error: function( data ) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
Subscribe(repo, function(data){
|
Subscribe(repo, function(data){
|
||||||
if (!data.jobs) {
|
if (!data.jobs) {
|
||||||
|
@ -81,6 +97,7 @@ function JobViewModel(repo, build, job, status) {
|
||||||
// the restart button and hide the tail button.
|
// the restart button and hide the tail button.
|
||||||
if (after !== "pending" && after !== "running") {
|
if (after !== "pending" && after !== "running") {
|
||||||
$("#restart").show();
|
$("#restart").show();
|
||||||
|
$("#cancel").hide();
|
||||||
$("#tail").hide();
|
$("#tail").hide();
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
|
@ -52,7 +52,8 @@ block content
|
||||||
div with exit code #{$job.ExitCode}
|
div with exit code #{$job.ExitCode}
|
||||||
|
|
||||||
div.build-btn-group
|
div.build-btn-group
|
||||||
button.btn.btn-info#restart restart
|
button.btn.btn-info.hidden#restart restart
|
||||||
|
button.btn.btn-info.hidden#cancel cancel
|
||||||
|
|
||||||
div.col-md-8
|
div.col-md-8
|
||||||
pre#output
|
pre#output
|
||||||
|
|
Loading…
Reference in a new issue