添加任务状态常量
Former-commit-id: 455cee1f2dc483d3da320e32e1c7709b0ef123a8
This commit is contained in:
parent
1e89049f10
commit
bc7288dc18
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
|
@ -32,7 +33,7 @@ func (l *DeleteTaskLogic) DeleteTask(req *types.DeleteTaskReq) error {
|
|||
return tx.Error
|
||||
}
|
||||
// 将子任务状态修改为待删除
|
||||
tx = l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", req.Id).Update("status", "WaitDelete")
|
||||
tx = l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", req.Id).Update("status", constants.WaitDelete)
|
||||
l.svcCtx.DbEngin.Where("task_id = ?", req.Id).Delete(&models.Cloud{}, req.Id)
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
|
|
|
@ -62,7 +62,7 @@ func (l *TaskListLogic) TaskList(req *types.TaskListReq) (resp *types.TaskListRe
|
|||
return nil, tx.Error
|
||||
}
|
||||
// 获取p端状态
|
||||
var pStatus string
|
||||
pStatus := "Unknown"
|
||||
key := fmt.Sprintf("ps_%s-%d", pInfo.Address, pInfo.Id)
|
||||
hGetAll := l.svcCtx.RedisClient.HGetAll(l.ctx, key)
|
||||
if hGetAll.Err() != nil {
|
||||
|
@ -74,9 +74,8 @@ func (l *TaskListLogic) TaskList(req *types.TaskListReq) (resp *types.TaskListRe
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if (time.Now().Unix() - parseInt) > 15 {
|
||||
pStatus = "Unknown"
|
||||
} else {
|
||||
if (time.Now().Unix() - parseInt) < 15 {
|
||||
|
||||
pStatus = "Normal"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package constants
|
||||
|
||||
// 任务类型
|
||||
// 任务状态类型
|
||||
const (
|
||||
Saved = "Saved"
|
||||
Saved = "Saved"
|
||||
Running = "Running"
|
||||
WaitDelete = "WaitDelete"
|
||||
Deleted = "Deleted"
|
||||
Completed = "Completed"
|
||||
Succeeded = "Succeeded"
|
||||
Failed = "Failed"
|
||||
)
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package enum
|
||||
|
||||
type AcStatus string
|
||||
|
||||
const (
|
||||
statR AcStatus = "statR"
|
||||
statC AcStatus = "statC"
|
||||
statQ AcStatus = "statQ"
|
||||
statW AcStatus = "statW"
|
||||
)
|
||||
|
||||
func (s AcStatus) String() string {
|
||||
switch s {
|
||||
case statR:
|
||||
return "Running"
|
||||
case statC:
|
||||
return "Completed"
|
||||
case statQ, statW:
|
||||
return "Pending"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package enum
|
||||
|
||||
type ExternalStatus string
|
||||
|
||||
const (
|
||||
EXTERNAL_RUNNING ExternalStatus = "running"
|
||||
EXTERNAL_COMPLETED ExternalStatus = "completed"
|
||||
EXTERNAL_PENDING ExternalStatus = "pending"
|
||||
EXTERNAL_SUCCEEDED ExternalStatus = "succeeded"
|
||||
EXTERNAL_FAILED ExternalStatus = "failed"
|
||||
)
|
||||
|
||||
func (s ExternalStatus) String() string {
|
||||
switch s {
|
||||
case EXTERNAL_RUNNING:
|
||||
return "Running"
|
||||
case EXTERNAL_COMPLETED:
|
||||
return "Completed"
|
||||
case EXTERNAL_PENDING:
|
||||
return "Pending"
|
||||
case EXTERNAL_SUCCEEDED:
|
||||
return "Succeeded"
|
||||
case EXTERNAL_FAILED:
|
||||
return "Failed"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package enum
|
||||
|
||||
type Partner string
|
||||
|
||||
const (
|
||||
AC Partner = "ac"
|
||||
TH Partner = "th"
|
||||
KubeNative Partner = "kubeNative"
|
||||
ModelArts Partner = "modelArts"
|
||||
)
|
||||
|
||||
func (p Partner) String() string {
|
||||
switch p {
|
||||
case AC:
|
||||
return "曙光超算"
|
||||
case KubeNative:
|
||||
return "长沙云算"
|
||||
case ModelArts:
|
||||
return "南京智算"
|
||||
case TH:
|
||||
return "天河超算"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package enum
|
||||
|
||||
type SynergyStatus int64
|
||||
|
||||
const (
|
||||
SYNERGIZED SynergyStatus = 0
|
||||
NOT_SYNERGIZED SynergyStatus = 1
|
||||
)
|
||||
|
||||
func (s SynergyStatus) String() string {
|
||||
switch s {
|
||||
case SYNERGIZED:
|
||||
return "已协同"
|
||||
case NOT_SYNERGIZED:
|
||||
return "未协同"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package enum
|
||||
|
||||
type State uint32
|
||||
|
||||
const (
|
||||
pending State = 0
|
||||
running State = 1
|
||||
suspended State = 2
|
||||
completed State = 3
|
||||
)
|
||||
|
||||
func (s State) String() string {
|
||||
switch s {
|
||||
case pending:
|
||||
return "Pending"
|
||||
case running:
|
||||
return "Running"
|
||||
case suspended:
|
||||
return "Suspended"
|
||||
case completed:
|
||||
return "Completed"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package cron
|
|||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
|
||||
"gorm.io/gorm"
|
||||
|
@ -13,7 +14,7 @@ func InitCron(svc *svc.ServiceContext) {
|
|||
svc.Cron.AddFunc("*/5 * * * * ?", func() {
|
||||
|
||||
var tasks []models.Task
|
||||
svc.DbEngin.Not("status not in ?", []string{"Deleted", "Succeeded", "Completed", "Failed"}).Find(&tasks)
|
||||
svc.DbEngin.Not("status not in ?", []string{constants.Deleted, constants.Succeeded, constants.Completed, constants.Failed}).Find(&tasks)
|
||||
for _, task := range tasks {
|
||||
var allStatus string
|
||||
tx := svc.DbEngin.Raw("SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.status) ,GROUP_CONCAT(DISTINCT a.status) ,GROUP_CONCAT(DISTINCT c.status))as status from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", task.Id).Scan(&allStatus)
|
||||
|
@ -27,12 +28,12 @@ func InitCron(svc *svc.ServiceContext) {
|
|||
continue
|
||||
}
|
||||
// 子任务包含失败状态 主任务则失败
|
||||
if strings.Contains(allStatus, "Failed") {
|
||||
updateTask(svc.DbEngin, &task, "Failed")
|
||||
if strings.Contains(allStatus, constants.Failed) {
|
||||
updateTask(svc.DbEngin, &task, constants.Failed)
|
||||
continue
|
||||
}
|
||||
if strings.Contains(allStatus, "Running") {
|
||||
updateTask(svc.DbEngin, &task, "Running")
|
||||
if strings.Contains(allStatus, constants.Running) {
|
||||
updateTask(svc.DbEngin, &task, constants.Running)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package pcmcorelogic
|
|||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
||||
"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/rpc/client/pcmcore"
|
||||
|
@ -36,7 +37,7 @@ func (l *InfoListLogic) InfoList(in *pcmcore.InfoListReq) (*pcmcore.InfoListResp
|
|||
var hpcModelList []models.Hpc
|
||||
findModelList(in.ParticipantId, l.svcCtx.DbEngin, &hpcModelList)
|
||||
utils.Convert(hpcModelList, &result.CloudInfoList)
|
||||
case "Kubernetes":
|
||||
case constants.Kubernetes:
|
||||
var cloudModelList []models.Cloud
|
||||
findModelList(in.ParticipantId, l.svcCtx.DbEngin, &cloudModelList)
|
||||
utils.Convert(cloudModelList, &result.CloudInfoList)
|
||||
|
|
|
@ -2,6 +2,7 @@ package pcmcorelogic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
|
||||
"time"
|
||||
|
@ -37,7 +38,7 @@ func (l *SyncInfoLogic) SyncInfo(in *pcmCore.SyncInfoReq) (*pcmCore.SyncInfoResp
|
|||
var kind string
|
||||
l.svcCtx.DbEngin.Raw("select type as kind from sc_participant_phy_info where id = ?", in.ParticipantId).Scan(&kind)
|
||||
switch kind {
|
||||
case "Kubernetes":
|
||||
case constants.Kubernetes:
|
||||
for _, cloudInfo := range in.CloudInfoList {
|
||||
l.svcCtx.DbEngin.Exec("update cloud set status = ?,start_time = ?,running_time = ?,result = ? where participant_id = ? and task_id = ? and namespace = ? and name = ?",
|
||||
cloudInfo.Status, cloudInfo.StartTime, cloudInfo.RunningTime, cloudInfo.Result, in.ParticipantId, cloudInfo.TaskId, cloudInfo.Namespace, cloudInfo.Name)
|
||||
|
|
Loading…
Reference in New Issue