增加集群部署支持,修复定时任务分组添加后选项不显示

This commit is contained in:
孟帅
2023-07-26 16:49:09 +08:00
parent 996ed818ee
commit 12bf36cd15
22 changed files with 1185 additions and 529 deletions

View 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
}

View File

@@ -14,8 +14,6 @@ var (
RootPtah string
// SysType 操作系统类型 windows | linux
SysType = runtime.GOOS
// Blacklists 黑名单列表
Blacklists map[string]struct{}
// JaegerSwitch 链路追踪开关
JaegerSwitch bool
)

View File

@@ -51,6 +51,9 @@ func Init(ctx context.Context) {
// 加载超管数据
service.AdminMember().LoadSuperAdmin(ctx)
// 订阅集群同步
SubscribeClusterSync(ctx)
}
// LoggingServeLogHandler 服务日志处理