feat: config

pull/2997/head
icey-yu 9 months ago
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"
@ -20,8 +19,14 @@ const (
var (
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…
Cancel
Save