你确认删除该任务么?此任务一旦删除不可恢复。
+diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 1124e3470..da6baa169 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -34,6 +34,7 @@ type Cloudbrain struct { ContainerIp string CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + DeletedAt time.Time `xorm:"deleted"` CanDebug bool `xorm:"-"` User *User `xorm:"-"` @@ -359,3 +360,12 @@ func updateJob(e Engine, job *Cloudbrain) error { _, err := sess.Cols("status", "container_id", "container_ip").Update(job) return err } + +func DeleteJob(job *Cloudbrain) error { + return deleteJob(x, job) +} + +func deleteJob(e Engine, job *Cloudbrain) error { + _, err := e.ID(job.ID).Delete(job) + return err +} diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 14160ec94..0d7937c5d 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -253,6 +253,29 @@ func CloudBrainStop(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } +func CloudBrainDel(ctx *context.Context) { + var jobID = ctx.Params(":jobid") + task, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + ctx.ServerError("GetCloudbrainByJobID failed", err) + return + } + + if task.Status != string(models.JobStopped) { + log.Error("the job(%s) has not been stopped", task.JobName) + ctx.ServerError("the job has not been stopped", errors.New("the job has not been stopped")) + return + } + + err = models.DeleteJob(task) + if err != nil { + ctx.ServerError("DeleteJob failed", err) + return + } + + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") +} + func downloadCode(repo *models.Repository, codePath string) error { if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{}); err != nil { log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 814af1fd9..c7f969e76 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -899,6 +899,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/debug", reqRepoCloudBrainReader, repo.CloudBrainDebug) m.Post("/commit_image", reqRepoCloudBrainWriter, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) m.Post("/stop", reqRepoCloudBrainWriter, repo.CloudBrainStop) + m.Post("/del", reqRepoCloudBrainWriter, repo.CloudBrainDel) }) m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index 5361db7dd..18c5053e2 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -1,4 +1,176 @@ + {{template "base/head" .}} + + +
你确认删除该任务么?此任务一旦删除不可恢复。
+