From c8d5cd6eba65fee449421f173c4fba0eedd63ac0 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Thu, 5 Sep 2024 18:31:41 +0800 Subject: [PATCH] feat: change 1s --- internal/push/push_handler.go | 18 +++++++++++++++++- pkg/rpccache/online.go | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/push/push_handler.go b/internal/push/push_handler.go index 00f9c01fb..46a75e3f5 100644 --- a/internal/push/push_handler.go +++ b/internal/push/push_handler.go @@ -40,6 +40,8 @@ import ( "github.com/openimsdk/tools/utils/timeutil" "github.com/redis/go-redis/v9" "google.golang.org/protobuf/proto" + "math/rand" + "strconv" "time" ) @@ -67,6 +69,20 @@ func NewConsumerHandler(config *Config, offlinePusher offlinepush.OfflinePusher, return nil, err } userRpcClient := rpcclient.NewUserRpcClient(client, config.Share.RpcRegisterName.User, config.Share.IMAdminUserID) + for { + ctx := mcontext.SetOperationID(context.TODO(), strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)) + conns, err := userRpcClient.Discov.GetConns( + ctx, + config.Share.RpcRegisterName.User, + ) + if err != nil || len(conns) == 0 { + time.Sleep(time.Second) + log.ZWarn(ctx, "waiting for user rpc", err) + } else { + break + } + } + consumerHandler.offlinePusher = offlinePusher consumerHandler.onlinePusher = NewOnlinePusher(client, config) consumerHandler.groupRpcClient = rpcclient.NewGroupRpcClient(client, config.Share.RpcRegisterName.Group) @@ -215,7 +231,7 @@ func (c *ConsumerHandler) Push2Group(ctx context.Context, groupID string, msg *s log.ZDebug(ctx, "Get group msg from msg_transfer and push msg", "msg", msg.String(), "groupID", groupID) defer func(duration time.Time) { t := time.Since(duration) - if t.Seconds() > 5 { + if t.Seconds() > 1 { log.ZWarn(ctx, "Get group msg from msg_transfer and push msg end", nil, "msg", msg.String(), "groupID", groupID, "time cost", t) } else { log.ZDebug(ctx, "Get group msg from msg_transfer and push msg end", "msg", msg.String(), "groupID", groupID, "time cost", t) diff --git a/pkg/rpccache/online.go b/pkg/rpccache/online.go index 943fff5db..94fbbe466 100644 --- a/pkg/rpccache/online.go +++ b/pkg/rpccache/online.go @@ -26,7 +26,6 @@ func NewOnlineCache(user rpcclient.UserRpcClient, group *GroupLocalCache, rdb re switch x.fullUserCache { case true: - time.Sleep(time.Second * 5) x.mapCache = cacheutil.NewCache[string, []int32]() if err := x.initUsersOnlineStatus(mcontext.SetOperationID(context.TODO(), strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10))); err != nil { return nil, err