forked from JointCloud/pcm-coordinator
fix scheduletaskbyyamllogic
This commit is contained in:
parent
0b0b1a5d97
commit
2c7cae3311
|
@ -2,6 +2,10 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
@ -24,7 +28,35 @@ func NewScheduleTaskByYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYamlReq) (resp *types.ScheduleTaskByYamlResp, err error) {
|
func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYamlReq) (resp *types.ScheduleTaskByYamlResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
bytes, err := json.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 构建主任务结构体
|
||||||
|
taskModel := models.Task{
|
||||||
|
Status: constants.Saved,
|
||||||
|
Description: req.Description,
|
||||||
|
Name: req.Name,
|
||||||
|
YamlString: string(bytes),
|
||||||
|
CommitTime: time.Now().String(),
|
||||||
|
}
|
||||||
|
// 保存任务数据到数据库
|
||||||
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
|
||||||
return
|
// 遍历子任务放入任务队列中
|
||||||
|
for _, task := range req.Tasks {
|
||||||
|
task.TaskId = taskModel.Id
|
||||||
|
// 将任务数据转换成消息体
|
||||||
|
reqMessage, err := json.Marshal(task)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
l.svcCtx.RedisClient.Publish(context.Background(), task.TaskType, reqMessage)
|
||||||
|
}
|
||||||
|
resp.TaskId = taskModel.Id
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
models2 "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
models2 "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/pcmcore"
|
pcmcore "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/pcmCore"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue