fix
zhangqian
2023-11-03 a9fa2fe7c72279cecc916bb63cee154cdea67b54
crontask/cron_task.go
@@ -3,11 +3,14 @@
import (
   "apsClient/conf"
   "apsClient/constvar"
   "apsClient/model"
   "apsClient/model/common"
   "apsClient/nsq"
   "apsClient/pkg/ecode"
   "apsClient/pkg/logx"
   "apsClient/serf"
   "apsClient/service"
   "apsClient/service/problem"
   "fmt"
   "github.com/go-co-op/gocron"
   "github.com/spf13/cast"
@@ -78,7 +81,13 @@
   if isMaster {
      s.Every(60).Seconds().Do(SyncProductionProgress) //同步生产数据
      s.Every(30).Seconds().Do(SyncTaskStatus)         //同步任务状态
      s.Every(10).Seconds().Do(CheckNsqConn)           //查询nsq连接
   }
   s.Every(20).Seconds().Do(QueryClusterStatus) //查询集群节点数量
   s.Every(30).Seconds().Do(ProblemCheck)       //问题诊断
   s.StartAsync()
   return nil
}
@@ -152,3 +161,35 @@
      logx.Errorf("send pull data msg error:%v, msg:%+v", err.Error(), msg)
   }
}
func QueryClusterStatus() {
   clusterStatus, nodeQuantity := serf.QueryClusterStatusAndNodeQuantity()
   conf.Conf.SerfClusterStatus = clusterStatus
   conf.Conf.ClusterNodeQuantity = nodeQuantity
}
func ProblemCheck() {
   problem.Check()
}
func CheckNsqConn() {
   var err error
   var status constvar.SystemStatusValue
   if nsq.Ping() {
      status = constvar.SystemStatusValueNormal
   } else {
      status = constvar.SystemStatusValueUnNormal
   }
   old, err := model.NewSystemStatusSearch().SetKey(constvar.SystemStatusKeyNsq).First()
   if err != nil {
      logx.Errorf("get nsq status err:%v", err)
      return
   }
   if old.Value == status {
      return
   }
   err = model.NewSystemStatusSearch().SetKey(constvar.SystemStatusKeyNsq).Updates(map[string]interface{}{"value": status})
   if err != nil {
      logx.Errorf("update nsq status err:%v", err)
   }
}