package cloudbrain import ( "errors" "fmt" "strconv" "time" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/models" ) func GenerateTask(ctx *context.Context, image, command string) error { nowStr := strconv.FormatInt(time.Now().Unix(), 10) jobName := fmt.Sprintf("%s%s", ctx.User.Name, nowStr[len(nowStr)-5:]) jobResult, err := CreateJob(jobName, models.CreateJobParams{ JobName: jobName, RetryCount: 1, GpuType: "debug", Image: image, TaskRoles: []models.TaskRole{ { Name: jobName, TaskNumber: 1, MinSucceededTaskCount: 1, MinFailedTaskCount: 1, CPUNumber: 2, GPUNumber: 1, MemoryMB: 16384, ShmMB: 8192, Command: command, NeedIBDevice: false, IsMainRole: false, }, }, }) if err != nil { return err } if jobResult.Code != "S000" { return errors.New(jobResult.Msg) } err = models.CreateCloudbrain(&models.Cloudbrain{ Status: int32(models.JobWaiting), UserID: ctx.User.ID, RepoID: ctx.Repo.Repository.ID, JobID: jobResult.Payload.JobID, }) if err != nil { return err } return nil }