package hpc import ( "context" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" "k8s.io/apimachinery/pkg/util/json" "time" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type CommitHpcTaskLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic { return &CommitHpcTaskLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) { // 构建主任务结构体 taskModel := models.Task{ Status: constants.Saved, Description: req.Description, Name: req.Name, CommitTime: time.Now(), } // 保存任务数据到数据库 tx := l.svcCtx.DbEngin.Create(&taskModel) if tx.Error != nil { return nil, tx.Error } env, _ := json.Marshal(req.Environment) hpcInfo := models.TaskHpc{ TaskId: taskModel.Id, ClusterId: 1706858330967773111, Name: taskModel.Name, Status: "Saved", CmdScript: req.CmdScript, StartTime: time.Now().String(), CardCount: req.CardCount, WorkDir: req.WorkDir, WallTime: req.WallTime, AppType: req.AppType, AppName: req.AppName, Queue: req.Queue, SubmitType: req.SubmitType, NNode: req.NNode, StdOutFile: req.StdOutFile, StdErrFile: req.StdErrFile, StdInput: req.StdInput, DeletedFlag: 0, CreatedBy: req.ParticipantId, CreatedTime: time.Now(), UpdatedBy: req.ParticipantId, UpdatedTime: time.Now(), Environment: string(env), } tx = l.svcCtx.DbEngin.Create(&hpcInfo) if tx.Error != nil { return nil, tx.Error } // 将任务数据转换成消息体 //reqMessage, err := json.Marshal(mqInfo) //if err != nil { // logx.Error(err) // return nil, err //} //publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage) //if publish.Err() != nil { // return nil, publish.Err() //} return }