检查检查时先检查集群是否已经部署服务,如果没有部署服务,则直接跳过

This commit is contained in:
刘祥超
2022-11-10 12:44:12 +08:00
parent dd0e26e7bc
commit e79264eefc
3 changed files with 19 additions and 4 deletions

View File

@@ -64,11 +64,11 @@ func (this *HealthCheckClusterTask) Run() {
if this.config.Interval == nil { if this.config.Interval == nil {
return return
} }
duration := this.config.Interval.Duration() var duration = this.config.Interval.Duration()
if duration <= 0 { if duration <= 0 {
return return
} }
ticker := utils.NewTicker(duration) var ticker = utils.NewTicker(duration)
goman.New(func() { goman.New(func() {
for ticker.Wait() { for ticker.Wait() {
err := this.Loop() err := this.Loop()

View File

@@ -52,10 +52,16 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
} }
var results = []*HealthCheckResult{} var results = []*HealthCheckResult{}
// 查询集群下的节点
nodes, err := models.NewNodeDAO().FindAllEnabledNodesWithClusterId(nil, this.clusterId, false) nodes, err := models.NewNodeDAO().FindAllEnabledNodesWithClusterId(nil, this.clusterId, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(nodes) == 0 {
return results, nil
}
for _, node := range nodes { for _, node := range nodes {
if !node.IsOn { if !node.IsOn {
continue continue
@@ -115,7 +121,7 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
var concurrent = 128 var concurrent = 128
wg := sync.WaitGroup{} var wg = sync.WaitGroup{}
wg.Add(countResults) wg.Add(countResults)
for i := 0; i < concurrent; i++ { for i := 0; i < concurrent; i++ {
go func() { go func() {

View File

@@ -70,7 +70,16 @@ func (this *HealthCheckTask) Loop() error {
// 启动新的或更新老的 // 启动新的或更新老的
for _, cluster := range clusters { 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{} var config = &serverconfigs.HealthCheckConfig{}
if len(cluster.HealthCheck) > 0 { if len(cluster.HealthCheck) > 0 {