diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index a18da3fe5..82d32951b 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -6,7 +6,9 @@ package repo import ( + "code.gitea.io/gitea/modules/setting" "net/http" + "os" "strconv" "strings" @@ -237,7 +239,7 @@ func DelTrainJobVersion(ctx *context.APIContext) { JobID: jobID, }) if err != nil { - ctx.ServerError("get VersionListCount faild", err) + ctx.ServerError("get VersionListCount failed", err) return } if VersionListCount > 0 { @@ -255,6 +257,8 @@ func DelTrainJobVersion(ctx *context.APIContext) { return } } + } else { //已删除该任务下的所有版本 + deleteJobStorage(task.JobName) } ctx.JSON(http.StatusOK, map[string]interface{}{ @@ -321,3 +325,21 @@ func ModelList(ctx *context.APIContext) { "PageIsCloudBrain": true, }) } + +func deleteJobStorage(jobName string) error { + //delete local + localJobPath := setting.JobPath + jobName + err := os.RemoveAll(localJobPath) + if err != nil { + log.Error("RemoveAll(%s) failed:%v", localJobPath, err) + } + + //delete oss + dirPath := setting.CodePathPrefix + jobName + "/" + err = storage.ObsRemoveObject(setting.Bucket, dirPath) + if err != nil { + log.Error("ObsRemoveObject(%s) failed:%v", localJobPath, err) + } + + return nil +} diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 5a68c298f..5503c7b35 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -567,7 +567,7 @@ func CloudBrainDel(ctx *context.Context) { return } - deleteJobName(task.JobName, models.TypeCloudBrainOne) + deleteJobStorage(task.JobName, models.TypeCloudBrainOne) ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } @@ -842,7 +842,7 @@ func mkModelPath(modelPath string) error { return nil } -func deleteJobName(jobName string, cloudbrainType int) error { +func deleteJobStorage(jobName string, cloudbrainType int) error { //delete local localJobPath := setting.JobPath + jobName err := os.RemoveAll(localJobPath)