mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-26 13:12:12 +08:00
feat: config
This commit is contained in:
parent
fa79fac6d5
commit
8acd21e180
@ -158,6 +158,12 @@ func compareAndSave[T any](c *gin.Context, old any, req *apistruct.SetConfigReq,
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) ResetConfig(c *gin.Context) {
|
||||
go cm.restart(c)
|
||||
apiresp.GinSuccess(c, nil)
|
||||
}
|
||||
|
||||
func (cm *ConfigManager) restart(c *gin.Context) {
|
||||
<-etcd.CanRestart
|
||||
type initConf struct {
|
||||
old any
|
||||
new any
|
||||
@ -214,5 +220,5 @@ func (cm *ConfigManager) ResetConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
apiresp.GinSuccess(c, nil)
|
||||
etcd.CanRestart <- struct{}{}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/openimsdk/tools/errs"
|
||||
@ -19,9 +18,15 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
ShutDowns []func() error
|
||||
ShutDowns []func() error
|
||||
CanRestart chan struct{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
CanRestart = make(chan struct{}, 1)
|
||||
CanRestart <- struct{}{}
|
||||
}
|
||||
|
||||
func RegisterShutDown(shutDown ...func() error) {
|
||||
ShutDowns = append(ShutDowns, shutDown...)
|
||||
}
|
||||
@ -29,7 +34,6 @@ func RegisterShutDown(shutDown ...func() error) {
|
||||
type ConfigManager struct {
|
||||
client *clientv3.Client
|
||||
watchConfigNames []string
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
func BuildKey(s string) string {
|
||||
@ -57,12 +61,12 @@ func (c *ConfigManager) Watch(ctx context.Context) {
|
||||
for _, event := range watchResp.Events {
|
||||
if event.IsModify() {
|
||||
if datautil.Contain(string(event.Kv.Key), c.watchConfigNames...) {
|
||||
c.lock.Lock()
|
||||
<-CanRestart
|
||||
err := restartServer(ctx)
|
||||
if err != nil {
|
||||
log.ZError(ctx, "restart server err", err)
|
||||
CanRestart <- struct{}{}
|
||||
}
|
||||
c.lock.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user