mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-02 09:22:11 +08:00
feat: init
This commit is contained in:
parent
04f56a9c00
commit
16fd28f39f
@ -2,6 +2,7 @@ package rpccache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/openimsdk/protocol/user"
|
"github.com/openimsdk/protocol/user"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -95,8 +96,10 @@ func (o *OnlineCache) initUsersOnlineStatus(ctx context.Context) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
totalSet atomic.Int64
|
totalSet atomic.Int64
|
||||||
gr, _ = errgroup.WithContext(ctx)
|
maxTries = 5
|
||||||
|
retryInterval = time.Second * 5
|
||||||
|
gr, _ = errgroup.WithContext(ctx)
|
||||||
)
|
)
|
||||||
gr.SetLimit(10)
|
gr.SetLimit(10)
|
||||||
|
|
||||||
@ -116,35 +119,33 @@ func (o *OnlineCache) initUsersOnlineStatus(ctx context.Context) error {
|
|||||||
|
|
||||||
gr.Go(func() error {
|
gr.Go(func() error {
|
||||||
var (
|
var (
|
||||||
usersStatus []*user.OnlineStatus
|
usersStatus []*user.OnlineStatus
|
||||||
resp *user.GetAllUserIDResp
|
resp *user.GetAllUserIDResp
|
||||||
err error
|
err error
|
||||||
maxTries = 5
|
retryOperation = func(operation func() error, operationName string) error {
|
||||||
|
for i := 0; i < maxTries; i++ {
|
||||||
|
if err = operation(); err != nil {
|
||||||
|
log.ZWarn(ctx, fmt.Sprintf("initUsersOnlineStatus: %s failed", operationName), err, "page", page, "retries", i+1)
|
||||||
|
time.Sleep(retryInterval)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < maxTries; i++ {
|
if err = retryOperation(func() error {
|
||||||
resp, err = o.user.GetAllUserID(ctx, page, constant.ParamMaxLength)
|
resp, err = o.user.GetAllUserID(ctx, page, constant.ParamMaxLength)
|
||||||
if err != nil {
|
return err
|
||||||
log.ZWarn(ctx, "initUsersOnlineStatus: GetAllUserID failed", err, "page", page, "retries", i+1)
|
}, "GetAllUserID"); err != nil {
|
||||||
time.Sleep(time.Second * 5)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < maxTries; i++ {
|
if err = retryOperation(func() error {
|
||||||
usersStatus, err = o.user.GetUsersOnlinePlatform(ctx, resp.UserIDs)
|
usersStatus, err = o.user.GetUsersOnlinePlatform(ctx, resp.UserIDs)
|
||||||
if err != nil {
|
return err
|
||||||
log.ZError(ctx, "initUsersOnlineStatus: GetAllUserID failed", err, "page", page, "retries", i+1)
|
}, "GetUsersOnlinePlatform"); err != nil {
|
||||||
time.Sleep(time.Second * 5)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user