Merge remote-tracking branch 'origin/2.0' into 2.0_lee_2.0

This commit is contained in:
ll15074821352 2023-04-24 15:31:39 +08:00
commit fff57f74d4
2 changed files with 51 additions and 4 deletions

View File

@ -1,12 +1,59 @@
package logic
import (
"PCM/adaptor/PCM-CORE/model"
"PCM/adaptor/PCM-CORE/rpc/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"strings"
)
func InitCron(svc *svc.ServiceContext) {
svc.Cron.Start()
svc.Cron.AddFunc("*/10 * * * * ?", func() {
svc.DbEngin.Exec("")
svc.Cron.AddFunc("*/5 * * * * ?", func() {
var tasks []model.Task
svc.DbEngin.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)
if tx.Error != nil {
logx.Error(tx.Error)
}
// 子状态统一则修改主任务状态
statusArray := strings.Split(allStatus, ",")
if len(RemoveRepeatedElement(statusArray)) == 1 {
task.Status = statusArray[0]
svc.DbEngin.Updates(&task)
continue
}
// 子任务包含失败状态 主任务则失败
if strings.Contains(allStatus, "Failed") {
task.Status = "Failed"
svc.DbEngin.Updates(&task)
continue
}
if strings.Contains(allStatus, "Running") {
task.Status = "Running"
svc.DbEngin.Updates(&task)
}
}
})
}
func RemoveRepeatedElement(arr []string) (newArr []string) {
newArr = make([]string, 0)
for i := 0; i < len(arr); i++ {
repeat := false
for j := i + 1; j < len(arr); j++ {
if arr[i] == arr[j] {
repeat = true
break
}
}
if !repeat {
newArr = append(newArr, arr[i])
}
}
return
}

View File

@ -61,9 +61,9 @@ func InitCron(svc *svc.ServiceContext) {
infoList.CloudInfoList[index].RunningTime = time.Now().Sub(deployment.Status.Conditions[0].LastTransitionTime.Time).Milliseconds() / 1000
// 判断状态
if deployment.Status.ReadyReplicas == deployment.Status.Replicas {
infoList.CloudInfoList[index].Status = "running"
infoList.CloudInfoList[index].Status = "Running"
} else {
infoList.CloudInfoList[index].Status = "pending"
infoList.CloudInfoList[index].Status = "Pending"
}
}
}