mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 05:12:32 +08:00
增加集群部署支持,修复定时任务分组添加后选项不显示
This commit is contained in:
60
server/internal/global/cluster.go
Normal file
60
server/internal/global/cluster.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Package consts
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package global
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/hgrds/lock"
|
||||
"hotgo/internal/library/hgrds/pubsub"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
// SubscribeClusterSync 订阅集群同步,可以用来集中同步数据、状态等
|
||||
func SubscribeClusterSync(ctx context.Context) {
|
||||
isCluster := g.Cfg().MustGet(ctx, "hotgo.isCluster").Bool()
|
||||
if !isCluster {
|
||||
return
|
||||
}
|
||||
|
||||
// 系统配置
|
||||
if err := pubsub.Subscribe(consts.ClusterSyncSysconfig, service.SysConfig().ClusterSync); err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
|
||||
// 系统黑名单
|
||||
if err := pubsub.Subscribe(consts.ClusterSyncSysBlacklist, service.SysBlacklist().ClusterSync); err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
|
||||
// 超管
|
||||
if err := pubsub.Subscribe(consts.ClusterSyncSysSuperAdmin, service.AdminMember().ClusterSyncSuperAdmin); err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// PublishClusterSync 推送集群同步消息,如果没有开启集群部署,则不进行推送
|
||||
func PublishClusterSync(ctx context.Context, channel string, message interface{}) {
|
||||
isCluster := g.Cfg().MustGet(ctx, "hotgo.isCluster").Bool()
|
||||
if !isCluster {
|
||||
return
|
||||
}
|
||||
|
||||
mutex := lock.Mutex(fmt.Sprintf("%s:%s", "lock", channel))
|
||||
if err := mutex.Lock(ctx); err != nil {
|
||||
g.Log().Warningf(ctx, "PublishClusterSync %v lock err:%v", channel, err)
|
||||
return
|
||||
}
|
||||
_ = mutex.Unlock(ctx)
|
||||
|
||||
if _, err := pubsub.Publish(ctx, channel, message); err != nil {
|
||||
g.Log().Warningf(ctx, "PublishClusterSync %v err:%v", channel, err)
|
||||
}
|
||||
return
|
||||
}
|
@@ -14,8 +14,6 @@ var (
|
||||
RootPtah string
|
||||
// SysType 操作系统类型 windows | linux
|
||||
SysType = runtime.GOOS
|
||||
// Blacklists 黑名单列表
|
||||
Blacklists map[string]struct{}
|
||||
// JaegerSwitch 链路追踪开关
|
||||
JaegerSwitch bool
|
||||
)
|
||||
|
@@ -51,6 +51,9 @@ func Init(ctx context.Context) {
|
||||
|
||||
// 加载超管数据
|
||||
service.AdminMember().LoadSuperAdmin(ctx)
|
||||
|
||||
// 订阅集群同步
|
||||
SubscribeClusterSync(ctx)
|
||||
}
|
||||
|
||||
// LoggingServeLogHandler 服务日志处理
|
||||
|
Reference in New Issue
Block a user