Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/144tags/v1.21.12.1
| @@ -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) | |||||
| } | |||||
| @@ -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") | |||||
| } | |||||
| @@ -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 | ||||