Browse Source

创建云脑任务报错时,页面可继续操作

pull/270/head
lewis 3 years ago
parent
commit
cd0a64a6ae
1 changed files with 21 additions and 7 deletions
  1. +21
    -7
      routers/repo/cloudbrain.go

+ 21
- 7
routers/repo/cloudbrain.go View File

@@ -94,9 +94,8 @@ func jobNamePrefixValid(s string) string {
return re.ReplaceAllString(lowStr, "") return re.ReplaceAllString(lowStr, "")
} }


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

t := time.Now() t := time.Now()
var jobName = jobNamePrefixValid(cutString(ctx.User.Name, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:] var jobName = jobNamePrefixValid(cutString(ctx.User.Name, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
ctx.Data["job_name"] = jobName ctx.Data["job_name"] = jobName
@@ -104,7 +103,7 @@ func CloudBrainNew(ctx *context.Context) {
result, err := cloudbrain.GetImages() result, err := cloudbrain.GetImages()
if err != nil { if err != nil {
ctx.Data["error"] = err.Error() ctx.Data["error"] = err.Error()
log.Error("cloudbrain.GetImages failed:", err.Error(), ctx.Data["msgID"])
log.Error("cloudbrain.GetImages failed:", err.Error(), ctx.Data["MsgID"])
} }


for i, payload := range result.Payload.ImageInfo { for i, payload := range result.Payload.ImageInfo {
@@ -120,7 +119,7 @@ func CloudBrainNew(ctx *context.Context) {
resultPublic, err := cloudbrain.GetPublicImages() resultPublic, err := cloudbrain.GetPublicImages()
if err != nil { if err != nil {
ctx.Data["error"] = err.Error() ctx.Data["error"] = err.Error()
log.Error("cloudbrain.GetPublicImages failed:", err.Error(), ctx.Data["msgID"])
log.Error("cloudbrain.GetPublicImages failed:", err.Error(), ctx.Data["MsgID"])
} }


for i, payload := range resultPublic.Payload.ImageInfo { for i, payload := range resultPublic.Payload.ImageInfo {
@@ -135,8 +134,8 @@ func CloudBrainNew(ctx *context.Context) {


attachs, err := models.GetAllUserAttachments(ctx.User.ID) attachs, err := models.GetAllUserAttachments(ctx.User.ID)
if err != nil { if err != nil {
ctx.ServerError("GetAllUserAttachments failed:", err)
return
log.Error("GetAllUserAttachments failed: %v", err, ctx.Data["MsgID"])
return err
} }


ctx.Data["attachments"] = attachs ctx.Data["attachments"] = attachs
@@ -163,6 +162,16 @@ func CloudBrainNew(ctx *context.Context) {
ctx.Data["resource_specs"] = cloudbrain.ResourceSpecs.ResourceSpec ctx.Data["resource_specs"] = cloudbrain.ResourceSpecs.ResourceSpec
ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath
ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled

return nil
}

func CloudBrainNew(ctx *context.Context) {
err := cloudBrainNewDataPrepare(ctx)
if err != nil {
ctx.ServerError("get new cloudbrain info failed", err)
return
}
ctx.HTML(200, tplCloudBrainNew) ctx.HTML(200, tplCloudBrainNew)
} }


@@ -178,7 +187,8 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
resourceSpecId := form.ResourceSpecId resourceSpecId := form.ResourceSpecId


if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) && jobType != string(models.JobTypeSnn4imagenet) { if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) && jobType != string(models.JobTypeSnn4imagenet) {
log.Error("jobtype error:", jobType, ctx.Data["msgID"])
log.Error("jobtype error:", jobType, ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form) ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form)
return return
} }
@@ -186,11 +196,13 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
_, err := models.GetCloudbrainByName(jobName) _, err := models.GetCloudbrainByName(jobName)
if err == nil { if err == nil {
log.Error("the job name did already exist", ctx.Data["MsgID"]) log.Error("the job name did already exist", ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("the job name did already exist", tplCloudBrainNew, &form) ctx.RenderWithErr("the job name did already exist", tplCloudBrainNew, &form)
return return
} else { } else {
if !models.IsErrJobNotExist(err) { if !models.IsErrJobNotExist(err) {
log.Error("system error, %v", err, ctx.Data["MsgID"]) log.Error("system error, %v", err, ctx.Data["MsgID"])
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr("system error", tplCloudBrainNew, &form) ctx.RenderWithErr("system error", tplCloudBrainNew, &form)
return return
} }
@@ -201,6 +213,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {
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 {
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form)
return return
} }
@@ -224,6 +237,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {


err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType, gpuQueue, resourceSpecId) err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType, gpuQueue, resourceSpecId)
if err != nil { if err != nil {
cloudBrainNewDataPrepare(ctx)
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form)
return return
} }


Loading…
Cancel
Save