mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
fix: process add errors wrap. (#1862)
* fix: process add errors wrap. * fix: process add errors wrap.
This commit is contained in:
parent
55ca661d13
commit
c55e03dc70
@ -17,6 +17,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
@ -28,8 +29,6 @@ import (
|
|||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/constant"
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
"github.com/OpenIMSDK/tools/discoveryregistry"
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||||
"github.com/OpenIMSDK/tools/log"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/api"
|
"github.com/openimsdk/open-im-server/v3/internal/api"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
@ -44,55 +43,42 @@ func main() {
|
|||||||
apiCmd.AddPortFlag()
|
apiCmd.AddPortFlag()
|
||||||
apiCmd.AddApi(run)
|
apiCmd.AddApi(run)
|
||||||
if err := apiCmd.Execute(); err != nil {
|
if err := apiCmd.Execute(); err != nil {
|
||||||
log.ZError(context.Background(), "API command execution failed", err)
|
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(port int, proPort int) error {
|
func run(port int, proPort int) error {
|
||||||
log.ZInfo(context.Background(), "Openim api port:", "port", port, "proPort", proPort)
|
|
||||||
|
|
||||||
if port == 0 || proPort == 0 {
|
if port == 0 || proPort == 0 {
|
||||||
err := "port or proPort is empty:" + strconv.Itoa(port) + "," + strconv.Itoa(proPort)
|
err := "port or proPort is empty:" + strconv.Itoa(port) + "," + strconv.Itoa(proPort)
|
||||||
log.ZError(context.Background(), err, nil)
|
return errs.Wrap(fmt.Errorf(err))
|
||||||
return fmt.Errorf(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rdb, err := cache.NewRedis()
|
rdb, err := cache.NewRedis()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(context.Background(), "Failed to initialize Redis", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.ZInfo(context.Background(), "api start init discov client")
|
|
||||||
|
|
||||||
var client discoveryregistry.SvcDiscoveryRegistry
|
var client discoveryregistry.SvcDiscoveryRegistry
|
||||||
|
|
||||||
// Determine whether zk is passed according to whether it is a clustered deployment
|
// Determine whether zk is passed according to whether it is a clustered deployment
|
||||||
client, err = kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
client, err = kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(context.Background(), "Failed to initialize discovery register", err)
|
return errs.Wrap(err, "register discovery err")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.CreateRpcRootNodes(config.Config.GetServiceNames()); err != nil {
|
if err = client.CreateRpcRootNodes(config.Config.GetServiceNames()); err != nil {
|
||||||
log.ZError(context.Background(), "Failed to create RPC root nodes", err)
|
return errs.Wrap(err, "create rpc root nodes error")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.ZInfo(context.Background(), "api register public config to discov")
|
|
||||||
if err = client.RegisterConf2Registry(constant.OpenIMCommonConfigKey, config.Config.EncodeConfig()); err != nil {
|
if err = client.RegisterConf2Registry(constant.OpenIMCommonConfigKey, config.Config.EncodeConfig()); err != nil {
|
||||||
log.ZError(context.Background(), "Failed to register public config to discov", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.ZInfo(context.Background(), "api register public config to discov success")
|
|
||||||
router := api.NewGinRouter(client, rdb)
|
router := api.NewGinRouter(client, rdb)
|
||||||
if config.Config.Prometheus.Enable {
|
if config.Config.Prometheus.Enable {
|
||||||
p := ginprom.NewPrometheus("app", prommetrics.GetGinCusMetrics("Api"))
|
p := ginprom.NewPrometheus("app", prommetrics.GetGinCusMetrics("Api"))
|
||||||
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
||||||
p.Use(router)
|
p.Use(router)
|
||||||
}
|
}
|
||||||
log.ZInfo(context.Background(), "api init router success")
|
|
||||||
|
|
||||||
var address string
|
var address string
|
||||||
if config.Config.Api.ListenIP != "" {
|
if config.Config.Api.ListenIP != "" {
|
||||||
@ -100,13 +86,11 @@ func run(port int, proPort int) error {
|
|||||||
} else {
|
} else {
|
||||||
address = net.JoinHostPort("0.0.0.0", strconv.Itoa(port))
|
address = net.JoinHostPort("0.0.0.0", strconv.Itoa(port))
|
||||||
}
|
}
|
||||||
log.ZInfo(context.Background(), "start api server", "address", address, "OpenIM version", config.Version)
|
|
||||||
|
|
||||||
server := http.Server{Addr: address, Handler: router}
|
server := http.Server{Addr: address, Handler: router}
|
||||||
go func() {
|
go func() {
|
||||||
err = server.ListenAndServe()
|
err = server.ListenAndServe()
|
||||||
if err != nil && err != http.ErrServerClosed {
|
if err != nil && err != http.ErrServerClosed {
|
||||||
log.ZError(context.Background(), "api run failed", err, "address", address)
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -120,7 +104,6 @@ func run(port int, proPort int) error {
|
|||||||
|
|
||||||
// graceful shutdown operation.
|
// graceful shutdown operation.
|
||||||
if err := server.Shutdown(ctx); err != nil {
|
if err := server.Shutdown(ctx); err != nil {
|
||||||
log.ZError(context.Background(), "failed to api-server shutdown", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,10 @@
|
|||||||
package msgtransfer
|
package msgtransfer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
@ -69,40 +71,47 @@ func StartTransfer(prometheusPort int) error {
|
|||||||
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
||||||
msgModel := cache.NewMsgCacheModel(rdb)
|
msgModel := cache.NewMsgCacheModel(rdb)
|
||||||
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
|
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
|
||||||
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel)
|
msgDatabase, err := controller.NewCommonMsgDatabase(msgDocModel, msgModel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
conversationRpcClient := rpcclient.NewConversationRpcClient(client)
|
conversationRpcClient := rpcclient.NewConversationRpcClient(client)
|
||||||
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
||||||
msgTransfer := NewMsgTransfer(msgDatabase, &conversationRpcClient, &groupRpcClient)
|
msgTransfer, err := NewMsgTransfer(msgDatabase, &conversationRpcClient, &groupRpcClient)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return msgTransfer.Start(prometheusPort)
|
return msgTransfer.Start(prometheusPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMsgTransfer(msgDatabase controller.CommonMsgDatabase, conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient) *MsgTransfer {
|
func NewMsgTransfer(msgDatabase controller.CommonMsgDatabase, conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient) (*MsgTransfer, error) {
|
||||||
return &MsgTransfer{
|
historyCH, err := NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient)
|
||||||
historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient),
|
if err != nil {
|
||||||
historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase),
|
return nil, err
|
||||||
}
|
}
|
||||||
|
historyMongoCH, err := NewOnlineHistoryMongoConsumerHandler(msgDatabase)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MsgTransfer{
|
||||||
|
historyCH: historyCH,
|
||||||
|
historyMongoCH: historyMongoCH,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MsgTransfer) Start(prometheusPort int) error {
|
func (m *MsgTransfer) Start(prometheusPort int) error {
|
||||||
|
ctx := context.Background()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
fmt.Println("start msg transfer", "prometheusPort:", prometheusPort)
|
fmt.Println("start msg transfer", "prometheusPort:", prometheusPort)
|
||||||
if prometheusPort <= 0 {
|
if prometheusPort <= 0 {
|
||||||
return errors.New("prometheusPort not correct")
|
return errs.Wrap(errors.New("prometheusPort not correct"))
|
||||||
}
|
}
|
||||||
if config.Config.ChatPersistenceMysql {
|
|
||||||
// go m.persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(m.persistentCH)
|
go m.historyCH.historyConsumerGroup.RegisterHandleAndConsumer(ctx, m.historyCH)
|
||||||
} else {
|
go m.historyMongoCH.historyConsumerGroup.RegisterHandleAndConsumer(ctx, m.historyMongoCH)
|
||||||
fmt.Println("msg transfer not start mysql consumer")
|
|
||||||
}
|
|
||||||
go m.historyCH.historyConsumerGroup.RegisterHandleAndConsumer(m.historyCH)
|
|
||||||
go m.historyMongoCH.historyConsumerGroup.RegisterHandleAndConsumer(m.historyMongoCH)
|
|
||||||
// go m.modifyCH.modifyMsgConsumerGroup.RegisterHandleAndConsumer(m.modifyCH)
|
|
||||||
/*err := prome.StartPrometheusSrv(prometheusPort)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}*/
|
|
||||||
////////////////////////////
|
|
||||||
if config.Config.Prometheus.Enable {
|
if config.Config.Prometheus.Enable {
|
||||||
reg := prometheus.NewRegistry()
|
reg := prometheus.NewRegistry()
|
||||||
reg.MustRegister(
|
reg.MustRegister(
|
||||||
|
@ -87,7 +87,7 @@ func NewOnlineHistoryRedisConsumerHandler(
|
|||||||
database controller.CommonMsgDatabase,
|
database controller.CommonMsgDatabase,
|
||||||
conversationRpcClient *rpcclient.ConversationRpcClient,
|
conversationRpcClient *rpcclient.ConversationRpcClient,
|
||||||
groupRpcClient *rpcclient.GroupRpcClient,
|
groupRpcClient *rpcclient.GroupRpcClient,
|
||||||
) *OnlineHistoryRedisConsumerHandler {
|
) (*OnlineHistoryRedisConsumerHandler, error) {
|
||||||
var och OnlineHistoryRedisConsumerHandler
|
var och OnlineHistoryRedisConsumerHandler
|
||||||
och.msgDatabase = database
|
och.msgDatabase = database
|
||||||
och.msgDistributionCh = make(chan Cmd2Value) // no buffer channel
|
och.msgDistributionCh = make(chan Cmd2Value) // no buffer channel
|
||||||
@ -98,14 +98,15 @@ func NewOnlineHistoryRedisConsumerHandler(
|
|||||||
}
|
}
|
||||||
och.conversationRpcClient = conversationRpcClient
|
och.conversationRpcClient = conversationRpcClient
|
||||||
och.groupRpcClient = groupRpcClient
|
och.groupRpcClient = groupRpcClient
|
||||||
och.historyConsumerGroup = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{
|
var err error
|
||||||
|
och.historyConsumerGroup, err = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{
|
||||||
KafkaVersion: sarama.V2_0_0_0,
|
KafkaVersion: sarama.V2_0_0_0,
|
||||||
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
|
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
|
||||||
}, []string{config.Config.Kafka.LatestMsgToRedis.Topic},
|
}, []string{config.Config.Kafka.LatestMsgToRedis.Topic},
|
||||||
config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToRedis)
|
config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToRedis)
|
||||||
// statistics.NewStatistics(&och.singleMsgSuccessCount, config.Config.ModuleName.MsgTransferName, fmt.Sprintf("%d
|
// statistics.NewStatistics(&och.singleMsgSuccessCount, config.Config.ModuleName.MsgTransferName, fmt.Sprintf("%d
|
||||||
// second singleMsgCount insert to mongo", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
|
// second singleMsgCount insert to mongo", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
|
||||||
return &och
|
return &och, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) {
|
func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) {
|
||||||
|
@ -34,16 +34,21 @@ type OnlineHistoryMongoConsumerHandler struct {
|
|||||||
msgDatabase controller.CommonMsgDatabase
|
msgDatabase controller.CommonMsgDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOnlineHistoryMongoConsumerHandler(database controller.CommonMsgDatabase) *OnlineHistoryMongoConsumerHandler {
|
func NewOnlineHistoryMongoConsumerHandler(database controller.CommonMsgDatabase) (*OnlineHistoryMongoConsumerHandler, error) {
|
||||||
mc := &OnlineHistoryMongoConsumerHandler{
|
historyConsumerGroup, err := kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{
|
||||||
historyConsumerGroup: kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{
|
|
||||||
KafkaVersion: sarama.V2_0_0_0,
|
KafkaVersion: sarama.V2_0_0_0,
|
||||||
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
|
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
|
||||||
}, []string{config.Config.Kafka.MsgToMongo.Topic},
|
}, []string{config.Config.Kafka.MsgToMongo.Topic},
|
||||||
config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToMongo),
|
config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToMongo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mc := &OnlineHistoryMongoConsumerHandler{
|
||||||
|
historyConsumerGroup: historyConsumerGroup,
|
||||||
msgDatabase: database,
|
msgDatabase: database,
|
||||||
}
|
}
|
||||||
return mc
|
return mc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *OnlineHistoryMongoConsumerHandler) handleChatWs2Mongo(
|
func (mc *OnlineHistoryMongoConsumerHandler) handleChatWs2Mongo(
|
||||||
|
@ -14,19 +14,24 @@
|
|||||||
|
|
||||||
package push
|
package push
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
type Consumer struct {
|
type Consumer struct {
|
||||||
pushCh ConsumerHandler
|
pushCh ConsumerHandler
|
||||||
successCount uint64
|
successCount uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsumer(pusher *Pusher) *Consumer {
|
func NewConsumer(pusher *Pusher) (*Consumer, error) {
|
||||||
return &Consumer{
|
c, err := NewConsumerHandler(pusher)
|
||||||
pushCh: *NewConsumerHandler(pusher),
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return &Consumer{
|
||||||
|
pushCh: *c,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consumer) Start() {
|
func (c *Consumer) Start() {
|
||||||
// statistics.NewStatistics(&c.successCount, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to
|
|
||||||
// msg_gateway count", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
|
go c.pushCh.pushConsumerGroup.RegisterHandleAndConsumer(context.Background(), &c.pushCh)
|
||||||
go c.pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&c.pushCh)
|
|
||||||
}
|
}
|
||||||
|
@ -35,15 +35,19 @@ type ConsumerHandler struct {
|
|||||||
pusher *Pusher
|
pusher *Pusher
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsumerHandler(pusher *Pusher) *ConsumerHandler {
|
func NewConsumerHandler(pusher *Pusher) (*ConsumerHandler, error) {
|
||||||
var consumerHandler ConsumerHandler
|
var consumerHandler ConsumerHandler
|
||||||
consumerHandler.pusher = pusher
|
consumerHandler.pusher = pusher
|
||||||
consumerHandler.pushConsumerGroup = kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{
|
var err error
|
||||||
|
consumerHandler.pushConsumerGroup, err = kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{
|
||||||
KafkaVersion: sarama.V2_0_0_0,
|
KafkaVersion: sarama.V2_0_0_0,
|
||||||
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
|
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
|
||||||
}, []string{config.Config.Kafka.MsgToPush.Topic}, config.Config.Kafka.Addr,
|
}, []string{config.Config.Kafka.MsgToPush.Topic}, config.Config.Kafka.Addr,
|
||||||
config.Config.Kafka.ConsumerGroupID.MsgToPush)
|
config.Config.Kafka.ConsumerGroupID.MsgToPush)
|
||||||
return &consumerHandler
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &consumerHandler, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConsumerHandler) handleMs2PsChat(ctx context.Context, msg []byte) {
|
func (c *ConsumerHandler) handleMs2PsChat(ctx context.Context, msg []byte) {
|
||||||
|
@ -66,9 +66,12 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
|||||||
pusher: pusher,
|
pusher: pusher,
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
|
consumer, err := NewConsumer(pusher)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
consumer := NewConsumer(pusher)
|
|
||||||
consumer.Start()
|
consumer.Start()
|
||||||
}()
|
}()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -80,7 +80,10 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
|||||||
userRpcClient := rpcclient.NewUserRpcClient(client)
|
userRpcClient := rpcclient.NewUserRpcClient(client)
|
||||||
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
||||||
friendRpcClient := rpcclient.NewFriendRpcClient(client)
|
friendRpcClient := rpcclient.NewFriendRpcClient(client)
|
||||||
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel)
|
msgDatabase, err := controller.NewCommonMsgDatabase(msgDocModel, cacheModel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
s := &msgServer{
|
s := &msgServer{
|
||||||
Conversation: &conversationClient,
|
Conversation: &conversationClient,
|
||||||
User: &userRpcClient,
|
User: &userRpcClient,
|
||||||
|
@ -17,6 +17,7 @@ package tools
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -25,14 +26,13 @@ import (
|
|||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/log"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartTask() error {
|
func StartTask() error {
|
||||||
fmt.Println("cron task start, config", config.Config.ChatRecordsClearTime)
|
fmt.Println("cron task start, config", config.Config.ChatRecordsClearTime)
|
||||||
|
|
||||||
msgTool, err := InitMsgTool()
|
msgTool, err := InitMsgTool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -47,18 +47,16 @@ func StartTask() error {
|
|||||||
|
|
||||||
// register cron tasks
|
// register cron tasks
|
||||||
var crontab = cron.New()
|
var crontab = cron.New()
|
||||||
log.ZInfo(context.Background(), "start chatRecordsClearTime cron task", "cron config", config.Config.ChatRecordsClearTime)
|
fmt.Println("start chatRecordsClearTime cron task", "cron config", config.Config.ChatRecordsClearTime)
|
||||||
_, err = crontab.AddFunc(config.Config.ChatRecordsClearTime, cronWrapFunc(rdb, "cron_clear_msg_and_fix_seq", msgTool.AllConversationClearMsgAndFixSeq))
|
_, err = crontab.AddFunc(config.Config.ChatRecordsClearTime, cronWrapFunc(rdb, "cron_clear_msg_and_fix_seq", msgTool.AllConversationClearMsgAndFixSeq))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(context.Background(), "start allConversationClearMsgAndFixSeq cron failed", err)
|
return errs.Wrap(err)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.ZInfo(context.Background(), "start msgDestruct cron task", "cron config", config.Config.MsgDestructTime)
|
fmt.Println("start msgDestruct cron task", "cron config", config.Config.MsgDestructTime)
|
||||||
_, err = crontab.AddFunc(config.Config.MsgDestructTime, cronWrapFunc(rdb, "cron_conversations_destruct_msgs", msgTool.ConversationsDestructMsgs))
|
_, err = crontab.AddFunc(config.Config.MsgDestructTime, cronWrapFunc(rdb, "cron_conversations_destruct_msgs", msgTool.ConversationsDestructMsgs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(context.Background(), "start conversationsDestructMsgs cron failed", err)
|
return errs.Wrap(err)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// start crontab
|
// start crontab
|
||||||
|
@ -84,7 +84,10 @@ func InitMsgTool() (*MsgTool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
msgDatabase := controller.InitCommonMsgDatabase(rdb, mongo.GetDatabase())
|
msgDatabase, err := controller.InitCommonMsgDatabase(rdb, mongo.GetDatabase())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase())
|
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase())
|
||||||
ctxTx := tx.NewMongo(mongo.GetClient())
|
ctxTx := tx.NewMongo(mongo.GetClient())
|
||||||
userDatabase := controller.NewUserDatabase(
|
userDatabase := controller.NewUserDatabase(
|
||||||
|
4
pkg/common/db/cache/init_redis.go
vendored
4
pkg/common/db/cache/init_redis.go
vendored
@ -49,7 +49,7 @@ func NewRedis() (redis.UniversalClient, error) {
|
|||||||
overrideConfigFromEnv()
|
overrideConfigFromEnv()
|
||||||
|
|
||||||
if len(config.Config.Redis.Address) == 0 {
|
if len(config.Config.Redis.Address) == 0 {
|
||||||
return nil, errors.New("redis address is empty")
|
return nil, errs.Wrap(errors.New("redis address is empty"))
|
||||||
}
|
}
|
||||||
specialerror.AddReplace(redis.Nil, errs.ErrRecordNotFound)
|
specialerror.AddReplace(redis.Nil, errs.ErrRecordNotFound)
|
||||||
var rdb redis.UniversalClient
|
var rdb redis.UniversalClient
|
||||||
@ -77,7 +77,7 @@ func NewRedis() (redis.UniversalClient, error) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
err = rdb.Ping(ctx).Err()
|
err = rdb.Ping(ctx).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("redis ping %w", err)
|
return nil, errs.Wrap(fmt.Errorf("redis ping %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
redisClient = rdb
|
redisClient = rdb
|
||||||
|
@ -126,21 +126,32 @@ type CommonMsgDatabase interface {
|
|||||||
ConvertMsgsDocLen(ctx context.Context, conversationIDs []string)
|
ConvertMsgsDocLen(ctx context.Context, conversationIDs []string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommonMsgDatabase(msgDocModel unrelationtb.MsgDocModelInterface, cacheModel cache.MsgModel) CommonMsgDatabase {
|
func NewCommonMsgDatabase(msgDocModel unrelationtb.MsgDocModelInterface, cacheModel cache.MsgModel) (CommonMsgDatabase, error) {
|
||||||
|
producerToRedis, err := kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.LatestMsgToRedis.Topic)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
producerToMongo, err := kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.MsgToMongo.Topic)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
producerToPush, err := kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.MsgToPush.Topic)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &commonMsgDatabase{
|
return &commonMsgDatabase{
|
||||||
msgDocDatabase: msgDocModel,
|
msgDocDatabase: msgDocModel,
|
||||||
cache: cacheModel,
|
cache: cacheModel,
|
||||||
producer: kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.LatestMsgToRedis.Topic),
|
producer: producerToRedis,
|
||||||
producerToMongo: kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.MsgToMongo.Topic),
|
producerToMongo: producerToMongo,
|
||||||
producerToPush: kafka.NewKafkaProducer(config.Config.Kafka.Addr, config.Config.Kafka.MsgToPush.Topic),
|
producerToPush: producerToPush,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database) CommonMsgDatabase {
|
func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database) (CommonMsgDatabase, error) {
|
||||||
cacheModel := cache.NewMsgCacheModel(rdb)
|
cacheModel := cache.NewMsgCacheModel(rdb)
|
||||||
msgDocModel := unrelation.NewMsgMongoDriver(database)
|
msgDocModel := unrelation.NewMsgMongoDriver(database)
|
||||||
CommonMsgDatabase := NewCommonMsgDatabase(msgDocModel, cacheModel)
|
return NewCommonMsgDatabase(msgDocModel, cacheModel)
|
||||||
return CommonMsgDatabase
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type commonMsgDatabase struct {
|
type commonMsgDatabase struct {
|
||||||
|
@ -16,6 +16,7 @@ package mgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/constant"
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
@ -38,7 +39,7 @@ func NewConversationMongo(db *mongo.Database) (*ConversationMgo, error) {
|
|||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
return &ConversationMgo{coll: coll}, nil
|
return &ConversationMgo{coll: coll}, nil
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package mgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/mgoutil"
|
"github.com/OpenIMSDK/tools/mgoutil"
|
||||||
@ -36,7 +37,7 @@ func NewGroupMongo(db *mongo.Database) (relation.GroupModelInterface, error) {
|
|||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
return &GroupMgo{coll: coll}, nil
|
return &GroupMgo{coll: coll}, nil
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package mgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/constant"
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
"github.com/OpenIMSDK/tools/mgoutil"
|
"github.com/OpenIMSDK/tools/mgoutil"
|
||||||
@ -37,7 +38,7 @@ func NewGroupMember(db *mongo.Database) (relation.GroupMemberModelInterface, err
|
|||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
return &GroupMemberMgo{coll: coll}, nil
|
return &GroupMemberMgo{coll: coll}, nil
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package mgo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/mgoutil"
|
"github.com/OpenIMSDK/tools/mgoutil"
|
||||||
"github.com/OpenIMSDK/tools/pagination"
|
"github.com/OpenIMSDK/tools/pagination"
|
||||||
@ -36,7 +37,7 @@ func NewGroupRequestMgo(db *mongo.Database) (relation.GroupRequestModelInterface
|
|||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
return &GroupRequestMgo{coll: coll}, nil
|
return &GroupRequestMgo{coll: coll}, nil
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func NewUserMongo(db *mongo.Database) (relation.UserModelInterface, error) {
|
|||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
return &UserMgo{coll: coll}, nil
|
return &UserMgo{coll: coll}, nil
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ import (
|
|||||||
|
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"github.com/OpenIMSDK/tools/mw/specialerror"
|
"github.com/OpenIMSDK/tools/mw/specialerror"
|
||||||
"github.com/OpenIMSDK/tools/utils"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
|
||||||
)
|
)
|
||||||
@ -63,9 +61,9 @@ func NewMongo() (*Mongo, error) {
|
|||||||
time.Sleep(time.Second) // exponential backoff could be implemented here
|
time.Sleep(time.Second) // exponential backoff could be implemented here
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildMongoURI() string {
|
func buildMongoURI() string {
|
||||||
@ -150,7 +148,7 @@ func (m *Mongo) createMongoIndex(collection string, isUnique bool, keys ...strin
|
|||||||
|
|
||||||
_, err := indexView.CreateOne(context.Background(), index, opts)
|
_, err := indexView.CreateOne(context.Background(), index, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap(err, "CreateIndex")
|
return errs.Wrap(err, "CreateIndex")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ package kafka
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/log"
|
"github.com/OpenIMSDK/tools/log"
|
||||||
|
|
||||||
@ -36,7 +38,7 @@ type MConsumerGroupConfig struct {
|
|||||||
IsReturnErr bool
|
IsReturnErr bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMConsumerGroup(consumerConfig *MConsumerGroupConfig, topics, addrs []string, groupID string) *MConsumerGroup {
|
func NewMConsumerGroup(consumerConfig *MConsumerGroupConfig, topics, addrs []string, groupID string) (*MConsumerGroup, error) {
|
||||||
consumerGroupConfig := sarama.NewConfig()
|
consumerGroupConfig := sarama.NewConfig()
|
||||||
consumerGroupConfig.Version = consumerConfig.KafkaVersion
|
consumerGroupConfig.Version = consumerConfig.KafkaVersion
|
||||||
consumerGroupConfig.Consumer.Offsets.Initial = consumerConfig.OffsetsInitial
|
consumerGroupConfig.Consumer.Offsets.Initial = consumerConfig.OffsetsInitial
|
||||||
@ -49,26 +51,28 @@ func NewMConsumerGroup(consumerConfig *MConsumerGroupConfig, topics, addrs []str
|
|||||||
SetupTLSConfig(consumerGroupConfig)
|
SetupTLSConfig(consumerGroupConfig)
|
||||||
consumerGroup, err := sarama.NewConsumerGroup(addrs, groupID, consumerGroupConfig)
|
consumerGroup, err := sarama.NewConsumerGroup(addrs, groupID, consumerGroupConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
return nil, errs.Wrap(err, strings.Join(topics, ","), strings.Join(addrs, ","), groupID)
|
||||||
}
|
}
|
||||||
return &MConsumerGroup{
|
return &MConsumerGroup{
|
||||||
consumerGroup,
|
consumerGroup,
|
||||||
groupID,
|
groupID,
|
||||||
topics,
|
topics,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MConsumerGroup) GetContextFromMsg(cMsg *sarama.ConsumerMessage) context.Context {
|
func (mc *MConsumerGroup) GetContextFromMsg(cMsg *sarama.ConsumerMessage) context.Context {
|
||||||
return GetContextWithMQHeader(cMsg.Headers)
|
return GetContextWithMQHeader(cMsg.Headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MConsumerGroup) RegisterHandleAndConsumer(handler sarama.ConsumerGroupHandler) {
|
func (mc *MConsumerGroup) RegisterHandleAndConsumer(ctx context.Context, handler sarama.ConsumerGroupHandler) {
|
||||||
log.ZDebug(context.Background(), "register consumer group", "groupID", mc.groupID)
|
log.ZDebug(context.Background(), "register consumer group", "groupID", mc.groupID)
|
||||||
ctx := context.Background()
|
|
||||||
for {
|
for {
|
||||||
err := mc.ConsumerGroup.Consume(ctx, mc.topics, handler)
|
err := mc.ConsumerGroup.Consume(ctx, mc.topics, handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
log.ZWarn(ctx, "consume err", err, "topic", mc.topics, "groupID", mc.groupID)
|
||||||
|
}
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ type Producer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewKafkaProducer initializes a new Kafka producer.
|
// NewKafkaProducer initializes a new Kafka producer.
|
||||||
func NewKafkaProducer(addr []string, topic string) *Producer {
|
func NewKafkaProducer(addr []string, topic string) (*Producer, error) {
|
||||||
p := Producer{
|
p := Producer{
|
||||||
addr: addr,
|
addr: addr,
|
||||||
topic: topic,
|
topic: topic,
|
||||||
@ -87,17 +88,17 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
|
|||||||
for i := 0; i <= maxRetry; i++ {
|
for i := 0; i <= maxRetry; i++ {
|
||||||
p.producer, err = sarama.NewSyncProducer(p.addr, p.config)
|
p.producer, err = sarama.NewSyncProducer(p.addr, p.config)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return &p
|
return &p, nil
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second) // Wait before retrying
|
time.Sleep(1 * time.Second) // Wait before retrying
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic if unable to create producer after retries
|
// Panic if unable to create producer after retries
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Failed to create Kafka producer: " + err.Error())
|
return nil, errs.Wrap(errors.New("failed to create Kafka producer: " + err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &p
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// configureProducerAck configures the producer's acknowledgement level.
|
// configureProducerAck configures the producer's acknowledgement level.
|
||||||
|
@ -17,6 +17,7 @@ package startrpc
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -43,7 +44,6 @@ import (
|
|||||||
"github.com/OpenIMSDK/tools/discoveryregistry"
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||||
"github.com/OpenIMSDK/tools/mw"
|
"github.com/OpenIMSDK/tools/mw"
|
||||||
"github.com/OpenIMSDK/tools/network"
|
"github.com/OpenIMSDK/tools/network"
|
||||||
"github.com/OpenIMSDK/tools/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start rpc server.
|
// Start rpc server.
|
||||||
@ -61,20 +61,20 @@ func Start(
|
|||||||
net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort)),
|
net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort)),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errs.Wrap(err, network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort))
|
||||||
}
|
}
|
||||||
|
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap1(err)
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
||||||
registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP)
|
registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var reg *prometheus.Registry
|
var reg *prometheus.Registry
|
||||||
@ -96,7 +96,7 @@ func Start(
|
|||||||
|
|
||||||
err = rpcFn(client, srv)
|
err = rpcFn(client, srv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap1(err)
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
err = client.Register(
|
err = client.Register(
|
||||||
rpcRegisterName,
|
rpcRegisterName,
|
||||||
@ -105,7 +105,7 @@ func Start(
|
|||||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap1(err)
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg errgroup.Group
|
var wg errgroup.Group
|
||||||
@ -123,7 +123,7 @@ func Start(
|
|||||||
})
|
})
|
||||||
|
|
||||||
wg.Go(func() error {
|
wg.Go(func() error {
|
||||||
return utils.Wrap1(srv.Serve(listener))
|
return errs.Wrap(srv.Serve(listener))
|
||||||
})
|
})
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
@ -146,7 +146,7 @@ func Start(
|
|||||||
return gerr
|
return gerr
|
||||||
|
|
||||||
case <-time.After(15 * time.Second):
|
case <-time.After(15 * time.Second):
|
||||||
return utils.Wrap1(errors.New("timeout exit"))
|
return errs.Wrap(errors.New("timeout exit"))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user