Browse Source

add jobname to save model

tags/v1.21.12.1
palytoxin 5 years ago
parent
commit
08a99e159b
7 changed files with 35 additions and 20 deletions
  1. +3
    -3
      models/cloudbrain.go
  2. +3
    -3
      models/migrations/v141.go
  3. +1
    -0
      modules/auth/cloudbrain.go
  4. +7
    -12
      modules/cloudbrain/cloudbrain.go
  5. +15
    -1
      routers/repo/cloudbrain.go
  6. +1
    -1
      templates/repo/cloudbrain/index.tmpl
  7. +5
    -0
      templates/repo/cloudbrain/new.tmpl

+ 3
- 3
models/cloudbrain.go View File

@@ -18,9 +18,9 @@ const (
)

type Cloudbrain struct {
ID int64 `xorm:"pk autoincr"`
JobID string
// Title string `xorm:"INDEX NOT NULL"`
ID int64 `xorm:"pk autoincr"`
JobID string `xorm:"INDEX NOT NULL"`
JobName string
Status int32 `xorm:"INDEX"`
UserID int64 `xorm:"INDEX"`
RepoID int64 `xorm:"INDEX"`


+ 3
- 3
models/migrations/v141.go View File

@@ -9,9 +9,9 @@ import (

func addCloudBrainTable(x *xorm.Engine) error {
type Cloudbrain struct {
ID int64 `xorm:"pk autoincr"`
JobId string
// Title string `xorm:"INDEX NOT NULL"`
ID int64 `xorm:"pk autoincr"`
JobID string `xorm:"INDEX NOT NULL"`
JobName string
Status int32 `xorm:"INDEX"`
UserID int64 `xorm:"INDEX"`
RepoID int64 `xorm:"INDEX"`


+ 1
- 0
modules/auth/cloudbrain.go View File

@@ -7,6 +7,7 @@ import (

// CreateDatasetForm form for dataset page
type CreateCloudBrainForm struct {
JobName string `form:"job_name" binding:"Required"`
Image string `binding:"Required"`
Command string `binding:"Required"`
}


+ 7
- 12
modules/cloudbrain/cloudbrain.go View File

@@ -2,19 +2,13 @@ package cloudbrain

import (
"errors"
"fmt"
"strconv"
"time"

"code.gitea.io/gitea/modules/context"

"code.gitea.io/gitea/models"
)

func GenerateTask(ctx *context.Context, image, command string) error {
nowStr := strconv.FormatInt(time.Now().Unix(), 10)

jobName := fmt.Sprintf("%s%s", ctx.User.Name, nowStr[len(nowStr)-5:])
func GenerateTask(ctx *context.Context, jobName, image, command string) error {
jobResult, err := CreateJob(jobName, models.CreateJobParams{
JobName: jobName,
RetryCount: 1,
@@ -22,7 +16,7 @@ func GenerateTask(ctx *context.Context, image, command string) error {
Image: image,
TaskRoles: []models.TaskRole{
{
Name: jobName,
Name: "task1",
TaskNumber: 1,
MinSucceededTaskCount: 1,
MinFailedTaskCount: 1,
@@ -45,10 +39,11 @@ func GenerateTask(ctx *context.Context, image, command string) error {

var jobID = jobResult.Payload["jobId"].(string)
err = models.CreateCloudbrain(&models.Cloudbrain{
Status: int32(models.JobWaiting),
UserID: ctx.User.ID,
RepoID: ctx.Repo.Repository.ID,
JobID: jobID,
Status: int32(models.JobWaiting),
UserID: ctx.User.ID,
RepoID: ctx.Repo.Repository.ID,
JobID: jobID,
JobName: jobName,
})

if err != nil {


+ 15
- 1
routers/repo/cloudbrain.go View File

@@ -1,6 +1,9 @@
package repo

import (
"strconv"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base"
@@ -52,9 +55,19 @@ func CloudBrainIndex(ctx *context.Context) {
ctx.HTML(200, tplCloudBrainIndex)
}

func cutString(str string, lens int) string {
if len(str) < lens {
return str
}
return str[:lens]
}

func CloudBrainNew(ctx *context.Context) {
ctx.Data["PageIsCloudBrain"] = true

t := time.Now()
var jobName = cutString(ctx.User.Name, 5) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[:5]
ctx.Data["job_name"] = jobName
ctx.Data["image"] = "192.168.202.74:5000/user-images/deepo:v2.0"
ctx.Data["command"] = `pip3 install jupyterlab==1.1.4;service ssh stop;jupyter lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=\"/userhome\" --port=80 --NotebookApp.token=\"\" --LabApp.allow_origin=\"self https://cloudbrain.pcl.ac.cn\"`
ctx.HTML(200, tplCloudBrainNew)
@@ -62,9 +75,10 @@ func CloudBrainNew(ctx *context.Context) {

func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
ctx.Data["PageIsCloudBrain"] = true
jobName := form.JobName
image := form.Image
command := form.Command
err := cloudbrain.GenerateTask(ctx, image, command)
err := cloudbrain.GenerateTask(ctx, jobName, image, command)
if err != nil {
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form)
return


+ 1
- 1
templates/repo/cloudbrain/index.tmpl View File

@@ -36,7 +36,7 @@
<div class="five wide column">
<a class="title" href="{{$.Link}}/{{.JobID}}">
<span class="fitted">{{svg "octicon-tasklist" 16}}</span>
<span class="fitted">{{.JobID}}</span>
<span class="fitted">{{.JobName}}</span>
</a>
</div>
<div class="two wide column">


+ 5
- 0
templates/repo/cloudbrain/new.tmpl View File

@@ -10,6 +10,11 @@
New Cloudbrain task
</h3>
<div class="ui attached segment">
<br>
<div class="inline required field">
<label>任务名称</label>
<input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255">
</div>
<br>
<div class="inline required field">
<label>镜像</label>


Loading…
Cancel
Save