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.

scheduletaskbyyamllogic.go 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package core
  13. import (
  14. "context"
  15. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  16. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  17. "k8s.io/apimachinery/pkg/util/json"
  18. "time"
  19. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  20. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  21. "github.com/zeromicro/go-zero/core/logx"
  22. )
  23. type ScheduleTaskByYamlLogic struct {
  24. logx.Logger
  25. ctx context.Context
  26. svcCtx *svc.ServiceContext
  27. }
  28. func NewScheduleTaskByYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleTaskByYamlLogic {
  29. return &ScheduleTaskByYamlLogic{
  30. Logger: logx.WithContext(ctx),
  31. ctx: ctx,
  32. svcCtx: svcCtx,
  33. }
  34. }
  35. func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYamlReq) (resp *types.ScheduleTaskByYamlResp, err error) {
  36. resp = &types.ScheduleTaskByYamlResp{}
  37. bytes, err := json.Marshal(req)
  38. if err != nil {
  39. return nil, err
  40. }
  41. // 构建主任务结构体
  42. taskModel := models.Task{
  43. Status: constants.Saved,
  44. Description: req.Description,
  45. Name: req.Name,
  46. YamlString: string(bytes),
  47. CommitTime: time.Now(),
  48. NsID: req.NsID,
  49. }
  50. // 保存任务数据到数据库
  51. tx := l.svcCtx.DbEngin.Create(&taskModel)
  52. if tx.Error != nil {
  53. return nil, tx.Error
  54. }
  55. // 遍历子任务放入任务队列中
  56. for _, task := range req.Tasks {
  57. task.NsID = req.NsID
  58. task.TaskId = taskModel.Id
  59. // 将任务数据转换成消息体
  60. reqMessage, err := json.Marshal(task)
  61. if err != nil {
  62. logx.Error(err)
  63. return nil, err
  64. }
  65. publish := l.svcCtx.RedisClient.Publish(context.Background(), task.TaskType, reqMessage)
  66. if publish.Err() != nil {
  67. return nil, publish.Err()
  68. }
  69. }
  70. resp.TaskId = taskModel.Id
  71. return resp, nil
  72. }

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.