配置更新时立即向集群节点发消息

This commit is contained in:
刘祥超
2020-10-09 12:03:53 +08:00
parent 458187acd2
commit 6f4992561f
3 changed files with 30 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ import (
var lastVersion = int64(-1)
var sharedNodeConfig *nodeconfigs.NodeConfig
var changeNotify = make(chan bool, 8)
// 节点
type Node struct {
@@ -117,13 +118,22 @@ func (this *Node) syncConfig(isFirstTime bool) error {
// 启动同步计时器
func (this *Node) startSyncTimer() {
// TODO 这个时间间隔可以自行设置
ticker := time.NewTicker(30 * time.Second)
ticker := time.NewTicker(60 * time.Second)
go func() {
for range ticker.C {
err := this.syncConfig(false)
if err != nil {
logs.Error("NODE", "sync config error: "+err.Error())
continue
for {
select {
case <-ticker.C:
err := this.syncConfig(false)
if err != nil {
logs.Error("NODE", "sync config error: "+err.Error())
continue
}
case <-changeNotify:
err := this.syncConfig(false)
if err != nil {
logs.Error("NODE", "sync config error: "+err.Error())
continue
}
}
}
}()