forked from JointCloud/pcm-coordinator
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package hpc
|
|
|
|
import (
|
|
"context"
|
|
"gitlink.org.cn/jcce-pcm/utils/enum"
|
|
"strings"
|
|
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ListJobLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewListJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListJobLogic {
|
|
return &ListJobLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *ListJobLogic) ListJob(req *types.ListJobReq) (resp *types.ListJobResp, err error) {
|
|
|
|
resp = &types.ListJobResp{}
|
|
|
|
var tasks []types.Job
|
|
// 查询任务数据
|
|
tx := l.svcCtx.DbEngin.Raw("SELECT h.service_name as SlurmVersion,h.name,h.start_time as JobStartTime,h.running_time as JobRunTime,t.status as StateofJob from hpc h join task t on t.id = h.task_id and t.status != 'Completed'").Scan(&tasks)
|
|
if tx.Error != nil {
|
|
logx.Error(err)
|
|
return nil, tx.Error
|
|
}
|
|
for _, task := range tasks {
|
|
// 承接方转义
|
|
if task.SlurmVersion != "" {
|
|
var names []string
|
|
servicesName := strings.Split(task.SlurmVersion, ",")
|
|
for _, name := range servicesName {
|
|
names = append(names, enum.Partner(name).String())
|
|
}
|
|
task.SlurmVersion = strings.Join(names, ",")
|
|
}
|
|
resp.Jobs = append(resp.Jobs, types.Job{
|
|
SlurmVersion: task.SlurmVersion,
|
|
Name: task.Name,
|
|
JobStartTime: task.JobStartTime,
|
|
JobRunTime: task.JobRunTime + "s",
|
|
StateofJob: task.StateofJob,
|
|
})
|
|
|
|
}
|
|
resp.Code = 200
|
|
resp.Msg = "success"
|
|
resp.RecordCount = int32(len(resp.Jobs))
|
|
|
|
return resp, nil
|
|
}
|