From e79264eefc21afc0d00dd9643fe13001f59e9f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 10 Nov 2022 12:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=A3=80=E6=9F=A5=E6=97=B6?= =?UTF-8?q?=E5=85=88=E6=A3=80=E6=9F=A5=E9=9B=86=E7=BE=A4=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E9=83=A8=E7=BD=B2=E6=9C=8D=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E9=83=A8=E7=BD=B2=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=EF=BC=8C=E5=88=99=E7=9B=B4=E6=8E=A5=E8=B7=B3=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/tasks/health_check_cluster_task.go | 4 ++-- internal/tasks/health_check_executor.go | 8 +++++++- internal/tasks/health_check_task.go | 11 ++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/tasks/health_check_cluster_task.go b/internal/tasks/health_check_cluster_task.go index f1128b22..a65a5a46 100644 --- a/internal/tasks/health_check_cluster_task.go +++ b/internal/tasks/health_check_cluster_task.go @@ -64,11 +64,11 @@ func (this *HealthCheckClusterTask) Run() { if this.config.Interval == nil { return } - duration := this.config.Interval.Duration() + var duration = this.config.Interval.Duration() if duration <= 0 { return } - ticker := utils.NewTicker(duration) + var ticker = utils.NewTicker(duration) goman.New(func() { for ticker.Wait() { err := this.Loop() diff --git a/internal/tasks/health_check_executor.go b/internal/tasks/health_check_executor.go index fafae227..b542f77d 100644 --- a/internal/tasks/health_check_executor.go +++ b/internal/tasks/health_check_executor.go @@ -52,10 +52,16 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) { } var results = []*HealthCheckResult{} + + // 查询集群下的节点 nodes, err := models.NewNodeDAO().FindAllEnabledNodesWithClusterId(nil, this.clusterId, false) if err != nil { return nil, err } + if len(nodes) == 0 { + return results, nil + } + for _, node := range nodes { if !node.IsOn { continue @@ -115,7 +121,7 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) { var concurrent = 128 - wg := sync.WaitGroup{} + var wg = sync.WaitGroup{} wg.Add(countResults) for i := 0; i < concurrent; i++ { go func() { diff --git a/internal/tasks/health_check_task.go b/internal/tasks/health_check_task.go index 58a2ff21..9022f610 100644 --- a/internal/tasks/health_check_task.go +++ b/internal/tasks/health_check_task.go @@ -70,7 +70,16 @@ func (this *HealthCheckTask) Loop() error { // 启动新的或更新老的 for _, cluster := range clusters { - clusterId := int64(cluster.Id) + var clusterId = int64(cluster.Id) + + // 检查当前集群上是否有服务,如果尚没有部署服务,则直接跳过 + countServers, err := models.SharedServerDAO.CountAllEnabledServersWithNodeClusterId(nil, clusterId) + if err != nil { + return err + } + if countServers == 0 { + continue + } var config = &serverconfigs.HealthCheckConfig{} if len(cluster.HealthCheck) > 0 {