redis 접속 실패시 로그가 과도하게 남는 문제 수정
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
@ -211,6 +212,8 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
|
||||
// redis channel에서 유저가 보낸 메시지를 읽는 go rountine
|
||||
go func() {
|
||||
var pubsub *redis.PubSub
|
||||
waittimer := time.Second
|
||||
|
||||
for {
|
||||
if pubsub == nil {
|
||||
pubsub = ws.redisSync.Subscribe(ctx, ws.redisMsgChanName, ws.redisCmdChanName)
|
||||
@ -218,6 +221,8 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
|
||||
|
||||
raw, err := pubsub.ReceiveMessage(ctx)
|
||||
if err == nil {
|
||||
waittimer = time.Second
|
||||
|
||||
buffer := bytes.NewBuffer([]byte(raw.Payload))
|
||||
dec := gob.NewDecoder(buffer)
|
||||
|
||||
@ -241,6 +246,12 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
|
||||
pubsub.Close()
|
||||
pubsub = nil
|
||||
|
||||
time.Sleep(waittimer)
|
||||
waittimer = waittimer * 2
|
||||
if waittimer > time.Minute {
|
||||
waittimer = time.Minute
|
||||
}
|
||||
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user