From 150f38f9a494f650410e6e6cfc3e895ffe706546 Mon Sep 17 00:00:00 2001 From: "894646498@qq.com" <13786100335> Date: Mon, 24 Apr 2023 15:27:27 +0800 Subject: [PATCH] =?UTF-8?q?core=E7=AB=AF=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=9B=B4=E6=96=B0=E4=B8=BB=E8=A1=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PCM-CORE/rpc/internal/logic/cronlogic.go | 51 ++++++++++++++++++- .../rpc/internal/logic/cronlogic.go | 4 +- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/adaptor/PCM-CORE/rpc/internal/logic/cronlogic.go b/adaptor/PCM-CORE/rpc/internal/logic/cronlogic.go index 6495d90..9c3e02a 100644 --- a/adaptor/PCM-CORE/rpc/internal/logic/cronlogic.go +++ b/adaptor/PCM-CORE/rpc/internal/logic/cronlogic.go @@ -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 +} diff --git a/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/logic/cronlogic.go b/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/logic/cronlogic.go index a82e64b..999f79a 100644 --- a/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/logic/cronlogic.go +++ b/adaptor/PCM-K8S/PCM-K8S-NATIVE/rpc/internal/logic/cronlogic.go @@ -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" } } }