You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloudbrain.go 1.1 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package cloudbrain
  2. import (
  3. "errors"
  4. "code.gitea.io/gitea/modules/context"
  5. "code.gitea.io/gitea/models"
  6. )
  7. func GenerateTask(ctx *context.Context, jobName, image, command string) error {
  8. jobResult, err := CreateJob(jobName, models.CreateJobParams{
  9. JobName: jobName,
  10. RetryCount: 1,
  11. GpuType: "dgx",
  12. Image: image,
  13. TaskRoles: []models.TaskRole{
  14. {
  15. Name: "task1",
  16. TaskNumber: 1,
  17. MinSucceededTaskCount: 1,
  18. MinFailedTaskCount: 1,
  19. CPUNumber: 2,
  20. GPUNumber: 1,
  21. MemoryMB: 16384,
  22. ShmMB: 8192,
  23. Command: command,
  24. NeedIBDevice: false,
  25. IsMainRole: false,
  26. },
  27. },
  28. })
  29. if err != nil {
  30. return err
  31. }
  32. if jobResult.Code != "S000" {
  33. return errors.New(jobResult.Msg)
  34. }
  35. var jobID = jobResult.Payload["jobId"].(string)
  36. err = models.CreateCloudbrain(&models.Cloudbrain{
  37. Status: string(models.JobWaiting),
  38. UserID: ctx.User.ID,
  39. RepoID: ctx.Repo.Repository.ID,
  40. JobID: jobID,
  41. JobName: jobName,
  42. })
  43. if err != nil {
  44. return err
  45. }
  46. return nil
  47. }