forked from JointCloud/pcm-coordinator
fix
Signed-off-by: jagger <cossjie@foxmail.com>
Former-commit-id: 7ea02a9f7d
This commit is contained in:
parent
cf52f868ce
commit
ff7aae0a88
|
@ -111,17 +111,17 @@ type HpcInfo struct {
|
|||
}
|
||||
|
||||
type CloudInfo struct {
|
||||
Id uint `json:"id,omitempty"`
|
||||
TaskId int64 `json:"taskId,omitempty"`
|
||||
AdapterId uint `json:"adapterId,omitempty"`
|
||||
ClusterId uint `json:"clusterId,omitempty"`
|
||||
ClusterName string `json:"clusterName,omitempty"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
StartTime *time.Time `json:"startTime,omitempty"`
|
||||
YamlString string `json:"yamlString,omitempty"`
|
||||
Result string `json:"result,omitempty"`
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
Id uint `json:"id,omitempty,optional"`
|
||||
TaskId int64 `json:"taskId,omitempty,optional"`
|
||||
AdapterId uint `json:"adapterId,omitempty,optional"`
|
||||
ClusterId uint `json:"clusterId,omitempty,optional"`
|
||||
ClusterName string `json:"clusterName,omitempty,optional"`
|
||||
Kind string `json:"kind,omitempty,optional"`
|
||||
Status string `json:"status,omitempty,optional"`
|
||||
StartTime *time.Time `json:"startTime,omitempty,optional,string"`
|
||||
YamlString string `json:"yamlString,omitempty,optional"`
|
||||
Result string `json:"result,omitempty,optional"`
|
||||
Namespace string `json:"namespace,omitempty,optional"`
|
||||
}
|
||||
|
||||
type AiInfo struct {
|
||||
|
|
|
@ -2,14 +2,15 @@ package core
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/api/client"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PushTaskInfoLogic struct {
|
||||
|
@ -33,9 +34,14 @@ func (l *PushTaskInfoLogic) PushTaskInfo(req *clientCore.PushTaskInfoReq) (*clie
|
|||
switch kind {
|
||||
case 0:
|
||||
for _, cloudInfo := range req.CloudInfoList {
|
||||
l.svcCtx.DbEngin.Exec("update cloud set status = ?,start_time = ?,result = ? where participant_id = ? and id = ?",
|
||||
cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, req.AdapterId, cloudInfo.Id)
|
||||
syncTask(l.svcCtx.DbEngin, cloudInfo.TaskId)
|
||||
var taskId uint
|
||||
result := l.svcCtx.DbEngin.Table("task_cloud").Select("task_id").Where("cluster_name=? and adapter_id=? and kind=?", cloudInfo.ClusterName, cloudInfo.AdapterId, cloudInfo.Kind).Find(&taskId)
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.New("Record does not exist")
|
||||
}
|
||||
l.svcCtx.DbEngin.Exec("update task_cloud set status = ?,start_time = ?,result = ? where cluster_name = ? and adapter_id = ?",
|
||||
cloudInfo.Status, cloudInfo.StartTime, cloudInfo.Result, cloudInfo.ClusterName, cloudInfo.AdapterId)
|
||||
syncTask(l.svcCtx.DbEngin, int64(taskId))
|
||||
}
|
||||
case 2:
|
||||
for _, hpcInfo := range req.HpcInfoList {
|
||||
|
@ -63,7 +69,7 @@ func (l *PushTaskInfoLogic) PushTaskInfo(req *clientCore.PushTaskInfoReq) (*clie
|
|||
func syncTask(gorm *gorm.DB, taskId int64) {
|
||||
|
||||
var allStatus string
|
||||
tx := gorm.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 = ?", taskId).Scan(&allStatus)
|
||||
tx := gorm.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 task_cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?", taskId).Scan(&allStatus)
|
||||
if tx.Error != nil {
|
||||
logx.Error(tx.Error)
|
||||
}
|
||||
|
@ -79,7 +85,7 @@ func syncTask(gorm *gorm.DB, taskId int64) {
|
|||
|
||||
}
|
||||
if strings.Contains(allStatus, constants.Running) {
|
||||
updateTask(gorm, taskId, constants.Running)
|
||||
updateTaskRunning(gorm, taskId, constants.Running)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -93,6 +99,16 @@ func updateTask(gorm *gorm.DB, taskId int64, status string) {
|
|||
}
|
||||
}
|
||||
|
||||
func updateTaskRunning(gorm *gorm.DB, taskId int64, status string) {
|
||||
var task models.Task
|
||||
gorm.Where("id = ? ", taskId).Find(&task)
|
||||
if task.Status != status {
|
||||
task.Status = status
|
||||
task.StartTime = time.Now().Format("2006-01-02 15:04:05")
|
||||
gorm.Updates(&task)
|
||||
}
|
||||
}
|
||||
|
||||
func removeRepeatedElement(arr []string) (newArr []string) {
|
||||
newArr = make([]string, 0)
|
||||
for i := 0; i < len(arr); i++ {
|
||||
|
|
|
@ -13,7 +13,7 @@ type TaskCloudModel struct {
|
|||
ClusterName string `json:"clusterName" gorm:"not null;comment:集群名称"`
|
||||
Kind string `json:"kind" gorm:"comment:种类"`
|
||||
Status string `json:"status" gorm:"comment:状态"`
|
||||
StartTime *time.Time `json:"startTime" gorm:"comment:开始时间"`
|
||||
StartTime *time.Time `json:"startTime,string" gorm:"comment:开始时间"`
|
||||
YamlString string `json:"yamlString" gorm:"not null;comment:入参"`
|
||||
Result string `json:"result" gorm:"comment:运行结果"`
|
||||
Namespace string `json:"namespace" gorm:"comment:命名空间"`
|
||||
|
|
Loading…
Reference in New Issue