上传配置中心没有定时校验bug

This commit is contained in:
liwei 2022-09-19 17:23:54 +08:00
parent 8cf0ee5890
commit 714da99c01
4 changed files with 25 additions and 16 deletions

View File

@ -9,13 +9,14 @@
if [ $num -eq 0 ] if [ $num -eq 0 ]
then then
nohup $CMD > /dev/null 2>&1 & nohup $CMD > /dev/null 2>&1 &
# nohup $CMD >output.log 2>&1 & #nohup $CMD > $SERVICE.log 2>&1 &
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
echo "start failed, please check the log!" echo "start failed, please check the log!"
exit $? exit $?
else else
echo $! > $SERVICE.pid
# echo $! > $SERVICE.pid
echo "start success" echo "start success"
fi fi
else else
@ -26,13 +27,14 @@
} }
stop(){ stop(){
echo "stopping $SERVICE..." echo "stopping $SERVICE..."
kill -9 `cat $SERVICE.pid` #kill -9 `cat $SERVICE.pid`
kill -9 `ps -ef | grep $SERVICE | grep conf | awk '{print $2}'`
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
echo "stop failed, may be $SERVICE isn't running" echo "stop failed, may be $SERVICE isn't running"
exit $? exit $?
else else
rm -rf $SERVICE.pid #rm -rf $SERVICE.pid
echo "stop success" echo "stop success"
fi fi
} }

View File

@ -155,7 +155,10 @@ func (this *AgentMgrComp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadC
} }
this.module.Debugf("SendMsgToAllAgent: msg:%v", msg) this.module.Debugf("SendMsgToAllAgent: msg:%v", msg)
this.agents.Range(func(key, value any) bool { this.agents.Range(func(key, value any) bool {
value.(IAgent).WriteMsg(msg) agent := value.(IAgent)
if agent.UserId() != "" { //只发送登录用户
agent.WriteMsg(msg)
}
return true return true
}) })
return nil return nil

View File

@ -12,6 +12,7 @@ import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/cron"
"go_dreamfactory/lego/sys/log"
"google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/anypb"
) )
@ -52,29 +53,28 @@ func (this *ChatComp) Start() (err error) {
} else { } else {
var id cron.EntryID var id cron.EntryID
this.takes = make([]cron.EntryID, 0) this.takes = make([]cron.EntryID, 0)
for _, v := range v.(*cfg.GameChatSystem).GetDataList() { confs := v.(*cfg.GameChatSystem)
if v.Type == int32(comm.TimedNotice) { //处理定时任务
for k, v1 := range confs.GetDataMap() {
if v1.Type == int32(comm.TimedNotice) { //处理定时任务
weekStr := "" weekStr := ""
for _, w := range v.Week { for _, w := range v1.Week {
weekStr += fmt.Sprintf("%d,", w) weekStr += fmt.Sprintf("%d,", w)
} }
if len(weekStr) > 0 && len(weekStr) < 7 { if len(v1.Week) > 0 && len(v1.Week) < 7 {
weekStr = weekStr[0 : len(weekStr)-1] weekStr = weekStr[0 : len(weekStr)-1]
} else { } else {
weekStr = "*" weekStr = "*"
} }
cronStr := fmt.Sprintf("* %d %d * * %s", v.TimeM, v.TimeH, weekStr) cronStr := fmt.Sprintf("* %d %d * * %s", v1.TimeM, v1.TimeH, weekStr)
if id, err = cron.AddFunc(cronStr, this.chatNoticen(v)); err != nil { this.module.Debug("注册Chat广播公告消息", log.Field{Key: "cronStr", Value: cronStr}, log.Field{Key: "text", Value: v1.Text})
if id, err = cron.AddFunc(cronStr, this.chatNoticen(confs.GetDataMap()[k])); err != nil {
this.module.Errorf("cron.AddFunc:%s err:%v", cronStr, err) this.module.Errorf("cron.AddFunc:%s err:%v", cronStr, err)
continue continue
} }
this.takes = append(this.takes, id) this.takes = append(this.takes, id)
} }
} }
//测试代码
// if id, err = cron.AddFunc("0 */1 * * * ?", this.chatNoticen(&cfg.GameChatSystemData{Text: "测试公告系统"})); err != nil {
// this.module.Errorf("cron.AddFunc:%s err:%v", "0 */1 * * * ?", err)
// }
} }
}) })
return return
@ -89,6 +89,7 @@ func (this *ChatComp) chatNoticen(n *cfg.GameChatSystemData) func() {
Content: n.Text, Content: n.Text,
} }
data, _ := anypb.New(&pb.ChatMessagePush{Chat: msg}) data, _ := anypb.New(&pb.ChatMessagePush{Chat: msg})
this.module.Debug("广播公告消息", log.Field{Key: "chat", Value: msg})
if err := this.module.service.AcrossClusterBroadcast(context.Background(), msg.Stag, comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{ if err := this.module.service.AcrossClusterBroadcast(context.Background(), msg.Stag, comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{
MainType: string(comm.ModuleChat), MainType: string(comm.ModuleChat),
SubType: "message", SubType: "message",

View File

@ -47,7 +47,6 @@ type Configure struct {
func (this *Configure) Start() (err error) { func (this *Configure) Start() (err error) {
timer := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval)) timer := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
defer timer.Stop()
go func() { go func() {
locp: locp:
for { for {
@ -58,6 +57,7 @@ func (this *Configure) Start() (err error) {
this.checkConfigure() this.checkConfigure()
} }
} }
timer.Stop()
}() }()
return return
@ -177,6 +177,7 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er
//检查配置文件是否有更新 //检查配置文件是否有更新
func (this *Configure) checkConfigure() { func (this *Configure) checkConfigure() {
log.Debug("Check Configure Update")
if dir, err := ioutil.ReadDir(this.options.ConfigurePath); err != nil { if dir, err := ioutil.ReadDir(this.options.ConfigurePath); err != nil {
log.Errorf("[Configure Sys] checkConfigure err:%v", err) log.Errorf("[Configure Sys] checkConfigure err:%v", err)
} else { } else {
@ -190,8 +191,10 @@ func (this *Configure) checkConfigure() {
handle := this.configurehandles[v.Name] handle := this.configurehandles[v.Name]
this.hlock.RUnlock() this.hlock.RUnlock()
if err = this.loaderConfigure(v.Name, handle); err != nil { if err = this.loaderConfigure(v.Name, handle); err != nil {
log.Errorln(err)
return return
} }
log.Debug("UpDate Configure", log.Field{Key: "table", Value: v.Name})
for _, v := range handle.events { for _, v := range handle.events {
if v != nil { if v != nil {
go func(f func()) { go func(f func()) {