Browse Source

fix-143

tags/v1.21.7^2
lewis 4 years ago
parent
commit
7736ca2939
3 changed files with 32 additions and 3 deletions
  1. +6
    -2
      models/cloudbrain.go
  2. +12
    -0
      models/error.go
  3. +14
    -1
      routers/repo/cloudbrain.go

+ 6
- 2
models/cloudbrain.go View File

@@ -2,7 +2,6 @@ package models


import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"time" "time"
"xorm.io/xorm" "xorm.io/xorm"
@@ -569,7 +568,7 @@ func getRepoCloudBrain(cb *Cloudbrain) (*Cloudbrain, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
return nil, errors.New("cloudbrain task is not found")
return nil, ErrJobNotExist{}
} }
return cb, nil return cb, nil
} }
@@ -609,3 +608,8 @@ func deleteJob(e Engine, job *Cloudbrain) error {
_, err := e.ID(job.ID).Delete(job) _, err := e.ID(job.ID).Delete(job)
return err return err
} }

func GetCloudbrainByName(jobName string) (*Cloudbrain, error) {
cb := &Cloudbrain{JobName: jobName}
return getRepoCloudBrain(cb)
}

+ 12
- 0
models/error.go View File

@@ -1987,3 +1987,15 @@ func IsErrFileChunkNotExist(err error) bool {
_, ok := err.(ErrFileChunkNotExist) _, ok := err.(ErrFileChunkNotExist)
return ok return ok
} }

type ErrJobNotExist struct {
}

func IsErrJobNotExist(err error) bool {
_, ok := err.(ErrJobNotExist)
return ok
}

func (err ErrJobNotExist) Error() string {
return fmt.Sprintf("the job does not exist")
}

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

@@ -168,11 +168,24 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form) ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form)
return return
} }

_, err := models.GetCloudbrainByName(jobName)
if err == nil {
log.Error("the job name did already exist", ctx.Data["MsgID"])
ctx.RenderWithErr("the job name did already exist", tplCloudBrainNew, &form)
return
} else {
if !models.IsErrJobNotExist(err) {
log.Error("system error, %v", err, ctx.Data["MsgID"])
ctx.RenderWithErr("system error", tplCloudBrainNew, &form)
return
}
}
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
downloadCode(repo, codePath) downloadCode(repo, codePath)


modelPath := setting.JobPath + jobName + cloudbrain.ModelMountPath modelPath := setting.JobPath + jobName + cloudbrain.ModelMountPath
err := os.MkdirAll(modelPath, os.ModePerm)
err = os.MkdirAll(modelPath, os.ModePerm)
if err != nil { if err != nil {
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form)
return return


Loading…
Cancel
Save