mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-17 10:40:27 +08:00
配置更新时立即向集群节点发消息
This commit is contained in:
@@ -32,6 +32,7 @@ function build() {
|
|||||||
|
|
||||||
cp configs/api.template.yaml $DIST/configs
|
cp configs/api.template.yaml $DIST/configs
|
||||||
cp -R www $DIST/
|
cp -R www $DIST/
|
||||||
|
cp -R pages $DIST/
|
||||||
|
|
||||||
echo "building ..."
|
echo "building ..."
|
||||||
env GOOS=${1} GOARCH=${2} go build -o $DIST/bin/${NAME} -ldflags="-s -w" ../cmd/edge-node/main.go
|
env GOOS=${1} GOARCH=${2} go build -o $DIST/bin/${NAME} -ldflags="-s -w" ../cmd/edge-node/main.go
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ func (this *APIStream) loop() error {
|
|||||||
err = this.handlePurgeCache(message)
|
err = this.handlePurgeCache(message)
|
||||||
case messageconfigs.MessageCodePreheatCache: // 预热缓存
|
case messageconfigs.MessageCodePreheatCache: // 预热缓存
|
||||||
err = this.handlePreheatCache(message)
|
err = this.handlePreheatCache(message)
|
||||||
|
case messageconfigs.MessageCodeConfigChanged: // 配置变化
|
||||||
|
err = this.handleConfigChanged(message)
|
||||||
default:
|
default:
|
||||||
err = this.handleUnknownMessage(message)
|
err = this.handleUnknownMessage(message)
|
||||||
}
|
}
|
||||||
@@ -400,6 +402,17 @@ func (this *APIStream) handlePreheatCache(message *pb.NodeStreamMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理配置变化
|
||||||
|
func (this *APIStream) handleConfigChanged(message *pb.NodeStreamMessage) error {
|
||||||
|
select {
|
||||||
|
case changeNotify <- true:
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
this.replyOk(message.RequestId, "ok")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 处理未知消息
|
// 处理未知消息
|
||||||
func (this *APIStream) handleUnknownMessage(message *pb.NodeStreamMessage) error {
|
func (this *APIStream) handleUnknownMessage(message *pb.NodeStreamMessage) error {
|
||||||
this.replyFail(message.RequestId, "unknown message code '"+message.Code+"'")
|
this.replyFail(message.RequestId, "unknown message code '"+message.Code+"'")
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
var lastVersion = int64(-1)
|
var lastVersion = int64(-1)
|
||||||
var sharedNodeConfig *nodeconfigs.NodeConfig
|
var sharedNodeConfig *nodeconfigs.NodeConfig
|
||||||
|
var changeNotify = make(chan bool, 8)
|
||||||
|
|
||||||
// 节点
|
// 节点
|
||||||
type Node struct {
|
type Node struct {
|
||||||
@@ -117,13 +118,22 @@ func (this *Node) syncConfig(isFirstTime bool) error {
|
|||||||
// 启动同步计时器
|
// 启动同步计时器
|
||||||
func (this *Node) startSyncTimer() {
|
func (this *Node) startSyncTimer() {
|
||||||
// TODO 这个时间间隔可以自行设置
|
// TODO 这个时间间隔可以自行设置
|
||||||
ticker := time.NewTicker(30 * time.Second)
|
ticker := time.NewTicker(60 * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
for range ticker.C {
|
for {
|
||||||
err := this.syncConfig(false)
|
select {
|
||||||
if err != nil {
|
case <-ticker.C:
|
||||||
logs.Error("NODE", "sync config error: "+err.Error())
|
err := this.syncConfig(false)
|
||||||
continue
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user