forked from JointCloud/pcm-hpc
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"github.com/jinzhu/copier"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/client/pcmcore"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-slurm/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-slurm/slurm"
|
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
|
)
|
|
|
|
func InitCron(svc *svc.ServiceContext) {
|
|
svc.Cron.Start()
|
|
submitJobLogic := NewSubmitJobLogic(context.Background(), svc)
|
|
listLogic := NewListJobLogic(context.Background(), svc)
|
|
svc.Cron.AddFunc("*/5 * * * * ?", func() {
|
|
|
|
// 查询core端分发下来的任务列表
|
|
infoReq := pcmcore.InfoListReq{
|
|
Kind: "hpc",
|
|
}
|
|
infoList, err := svc.PcmCoreRpc.InfoList(context.Background(), &infoReq)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return
|
|
}
|
|
// 提交任务
|
|
submitJob(infoList, submitJobLogic)
|
|
// 查询运行中的任务列表同步信息
|
|
listReq := slurm.ListJobReq{}
|
|
listJob, err := listLogic.ListJob(&listReq)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return
|
|
}
|
|
for index, _ := range infoList.HpcInfoList {
|
|
for _, job := range listJob.Jobs {
|
|
if job.Name == infoList.HpcInfoList[index].Name {
|
|
copier.CopyWithOption(&infoList.HpcInfoList[index], job, copier.Option{Converters: tool.Converters})
|
|
infoList.HpcInfoList[index].JobId = job.JobId
|
|
infoList.HpcInfoList[index].StartTime = string(job.StartTime)
|
|
infoList.HpcInfoList[index].RunningTime = int64(job.EndTime - job.StartTime)
|
|
infoList.HpcInfoList[index].Status = job.JobState
|
|
infoList.HpcInfoList[index].Version = "slurm 2.6.9"
|
|
}
|
|
}
|
|
}
|
|
// 同步信息到core端
|
|
if len(infoList.HpcInfoList) != 0 {
|
|
syncInfoReq := pcmcore.SyncInfoReq{
|
|
Kind: "hpc",
|
|
HpcInfoList: infoList.HpcInfoList,
|
|
}
|
|
svc.PcmCoreRpc.SyncInfo(context.Background(), &syncInfoReq)
|
|
}
|
|
})
|
|
}
|
|
|
|
func submitJob(infoList *pcmcore.InfoListResp, submitJobLogic *SubmitJobLogic) {
|
|
for index, _ := range infoList.HpcInfoList {
|
|
if infoList.HpcInfoList[index].Status == "Saved" {
|
|
submitReq := slurm.SubmitJobReq{
|
|
Script: "",
|
|
Job: nil,
|
|
Jobs: nil,
|
|
}
|
|
jobResult, _ := submitJobLogic.SubmitJob(&submitReq)
|
|
// 任务提交成功
|
|
infoList.HpcInfoList[index].Status = "Pending"
|
|
infoList.HpcInfoList[index].JobId = string(jobResult.JobId)
|
|
}
|
|
}
|
|
}
|