|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package modelarts
-
- import (
- "code.gitea.io/gitea/modules/setting"
- "encoding/json"
- "path"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- )
-
- const (
- storageTypeOBS = "obs"
- autoStopDuration = 4 * 60 * 60
-
- DataSetMountPath = "/home/ma-user/work"
- NotebookEnv = "Python3"
- NotebookType = "Ascend"
- )
-
- var (
- poolInfos *models.PoolInfos
- FlavorInfos *models.FlavorInfos
- )
-
- func GenerateTask(ctx *context.Context, jobName, uuid, description string) error {
- dataActualPath := setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/"
- if poolInfos == nil {
- json.Unmarshal([]byte(setting.PoolInfos), &poolInfos)
- }
- jobResult, err := CreateJob(models.CreateNotebookParams{
- JobName: jobName,
- Description: description,
- ProfileID: setting.ProfileID,
- Flavor: setting.Flavor,
- Pool: models.Pool{
- ID: poolInfos.PoolInfo[0].PoolId,
- Name: poolInfos.PoolInfo[0].PoolName,
- Type: poolInfos.PoolInfo[0].PoolType,
- },
- Spec: models.Spec{
- Storage: models.Storage{
- Type: storageTypeOBS,
- Location: models.Location{
- Path: dataActualPath,
- },
- },
- AutoStop: models.AutoStop{
- Enable: true,
- Duration: autoStopDuration,
- },
- },
- })
- if err != nil {
- log.Error("CreateJob failed: %v", err.Error())
- return err
- }
-
- err = models.CreateCloudbrain(&models.Cloudbrain{
- Status: string(models.JobWaiting),
- UserID: ctx.User.ID,
- RepoID: ctx.Repo.Repository.ID,
- JobID: jobResult.ID,
- JobName: jobName,
- JobType: string(models.JobTypeDebug),
- Type: models.TypeCloudBrainTwo,
- })
-
- if err != nil {
- return err
- }
-
- return nil
- }
|