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.

schedulecanceltasklogic.go 2.0 kB

11 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package schedule
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/status"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  8. "strconv"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type ScheduleCancelTaskLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewScheduleCancelTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleCancelTaskLogic {
  19. return &ScheduleCancelTaskLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *ScheduleCancelTaskLogic) ScheduleCancelTask(req *types.CancelTaskReq) (resp *types.CancelTaskResp, err error) {
  26. task, err := l.svcCtx.Scheduler.AiService.Storage.GetTaskById(req.TaskId)
  27. if err != nil {
  28. return nil, err
  29. }
  30. if task == nil {
  31. return nil, errors.New("failed to cancel task, task not found")
  32. }
  33. // find ai tasks
  34. aitasks, err := l.svcCtx.Scheduler.AiStorages.GetAiTaskListById(task.Id)
  35. if err != nil {
  36. return nil, err
  37. }
  38. if len(aitasks) == 0 {
  39. return nil, errors.New("failed to cancel task, ai sub tasks have not been created")
  40. }
  41. // update status
  42. status.UpdateAiTask(l.svcCtx, aitasks...)
  43. t := aitasks[0]
  44. if t.Status != constants.Running {
  45. return nil, fmt.Errorf("failed to cancel task, ai sub tasks is %s", t.Status)
  46. }
  47. // assume a task has only one sub ai task
  48. err = l.svcCtx.Scheduler.AiService.AiExecutorAdapterMap[strconv.FormatInt(t.AdapterId, 10)][strconv.FormatInt(t.ClusterId, 10)].Stop(l.ctx, t.JobId)
  49. if err != nil {
  50. return nil, err
  51. }
  52. t.Status = constants.Cancelled
  53. err = l.svcCtx.Scheduler.AiService.Storage.UpdateAiTask(t)
  54. if err != nil {
  55. return nil, err
  56. }
  57. task.Status = constants.Cancelled
  58. err = l.svcCtx.Scheduler.AiService.Storage.UpdateTaskByModel(task)
  59. if err != nil {
  60. return nil, err
  61. }
  62. return resp, nil
  63. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.