redis 접속 실패시 로그가 과도하게 남는 문제 수정

This commit is contained in:
2023-10-26 16:42:17 +09:00
parent ebd1a89a58
commit 60d0c19256

View File

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
"time"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
"repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon"
@ -211,6 +212,8 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
// redis channel에서 유저가 보낸 메시지를 읽는 go rountine // redis channel에서 유저가 보낸 메시지를 읽는 go rountine
go func() { go func() {
var pubsub *redis.PubSub var pubsub *redis.PubSub
waittimer := time.Second
for { for {
if pubsub == nil { if pubsub == nil {
pubsub = ws.redisSync.Subscribe(ctx, ws.redisMsgChanName, ws.redisCmdChanName) 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) raw, err := pubsub.ReceiveMessage(ctx)
if err == nil { if err == nil {
waittimer = time.Second
buffer := bytes.NewBuffer([]byte(raw.Payload)) buffer := bytes.NewBuffer([]byte(raw.Payload))
dec := gob.NewDecoder(buffer) dec := gob.NewDecoder(buffer)
@ -241,6 +246,12 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
pubsub.Close() pubsub.Close()
pubsub = nil pubsub = nil
time.Sleep(waittimer)
waittimer = waittimer * 2
if waittimer > time.Minute {
waittimer = time.Minute
}
if ctx.Err() != nil { if ctx.Err() != nil {
break break
} }