Browse Source

stop

tags/v0.1.8
yuyuanshifu 4 years ago
parent
commit
ab71cf65a3
5 changed files with 56 additions and 2 deletions
  1. +5
    -0
      models/cloudbrain.go
  2. +31
    -0
      modules/cloudbrain/resty.go
  3. +11
    -0
      routers/repo/cloudbrain.go
  4. +1
    -0
      routers/routes/routes.go
  5. +8
    -2
      templates/repo/cloudbrain/index.tmpl

+ 5
- 0
models/cloudbrain.go View File

@@ -230,6 +230,11 @@ type CommitImageResult struct {
Payload map[string]interface{} `json:"payload"`
}

type StopJobResult struct {
Code string `json:"code"`
Msg string `json:"msg"`
}

func Cloudbrains(opts *CloudbrainsOptions) ([]*Cloudbrain, int64, error) {
sess := x.NewSession()
defer sess.Close()


+ 31
- 0
modules/cloudbrain/resty.go View File

@@ -181,3 +181,34 @@ sendjob:

return &result, nil
}

func StopJob(jobID string) error {
checkSetting()
client := getRestyClient()
var result models.StopJobResult

retry := 0

sendjob:
res, err := client.R().
SetHeader("Content-Type", "application/json").
SetAuthToken(TOKEN).
SetResult(&result).
Delete(HOST + "/rest-server/api/v1/jobs/" + jobID)

if err != nil {
return fmt.Errorf("resty StopJob: %v", err)
}

if result.Code == "S401" && retry < 1 {
retry++
_ = loginCloudbrain()
goto sendjob
}

if result.Code != Success {
return fmt.Errorf("StopJob err: %s", res.String())
}

return nil
}

+ 11
- 0
routers/repo/cloudbrain.go View File

@@ -213,6 +213,17 @@ func CloudBrainCommitImage(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain")
}

func CloudBrainStop(ctx *context.Context) {
var jobID = ctx.Params(":jobid")
err := cloudbrain.StopJob(jobID)
if err != nil {
log.Error("StopJob failed:", err.Error())
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{


+ 1
- 0
routers/routes/routes.go View File

@@ -897,6 +897,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/:jobid", reqRepoCloudBrainReader, repo.CloudBrainShow)
m.Get("/:jobid/debug", reqRepoCloudBrainReader, repo.CloudBrainDebug)
m.Post("/:jobid/commit_image", reqRepoCloudBrainReader, repo.CloudBrainCommitImage)
m.Post("/:jobid/stop", reqRepoCloudBrainReader, repo.CloudBrainStop)
m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew)
m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate)
}, context.RepoRef())


+ 8
- 2
templates/repo/cloudbrain/index.tmpl View File

@@ -63,12 +63,18 @@
</div>
<div class="two wide column">
<span class="ui text center clipboard">
<a class="title" href="{{$.Link}}/{{.JobID}}">
<a class="title" href="{{if not .CanDebug}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/commit_image{{end}}" style="{{if not .CanDebug}}color:#CCCCCC{{end}}">
<span class="fitted">镜像提交</span>
</a>
</span>
</div>

<div class="one wide column">
<span class="ui text center clipboard">
<a class="title" href="{{if ne .Status "RUNNING"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/stop/{{end}}" style="{{if ne .Status "RUNNING"}}color:#CCCCCC{{end}}">
<span class="fitted">停止</span>
</a>
</span>
</div>
</div>
</div>
{{end}}


Loading…
Cancel
Save