|
- /*
-
- Copyright (c) [2023] [pcm]
- [pcm-coordinator] is licensed under Mulan PSL v2.
- You can use this software according to the terms and conditions of the Mulan PSL v2.
- You may obtain a copy of Mulan PSL v2 at:
- http://license.coscl.org.cn/MulanPSL2
- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- See the Mulan PSL v2 for more details.
-
- */
-
- package hpc
-
- import (
- "context"
- "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/enum"
- "strings"
-
- "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 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
- }
|