feat(ws): implement WebSocket cluster mode with Redis Pub/Sub
Introduce a new WebSocket messaging architecture that supports both standalone and cluster modes. This allows for horizontal scaling of WebSocket servers by using Redis Pub/Sub to synchronize messages across multiple instances. Key changes: - Added `ws.MessagePublisher` interface to abstract message distribution. - Implemented `ws.Bus` to handle cluster-mode messaging via Redis. - Added `ws.OnlineTracker` to manage user online status across the cluster. - Refactored multiple services (Chat, Group, Push, Call, etc.) to use the new `MessagePublisher` instead of a concrete `ws.Hub`. - Added WebSocket configuration options (mode, instance ID, channel, TTL, heartbeat) to `config.yaml` and `config.go`. - Updated dependency injection with Wire to support the new publisher and Redis client. - Improved logging by replacing standard `log` with `zap` in several service components.
This commit is contained in:
@@ -2,12 +2,12 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"with_you/internal/model"
|
||||
"with_you/internal/repository"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -50,13 +50,18 @@ func (s *accountCleanupServiceImpl) CleanupExpiredAccounts(ctx context.Context)
|
||||
var deletedCount int64
|
||||
for _, user := range users {
|
||||
if err := s.anonymizeAndDeleteUser(ctx, user); err != nil {
|
||||
log.Printf("[AccountCleanup] failed to cleanup user %s: %v", user.ID, err)
|
||||
zap.L().Error("Failed to cleanup user",
|
||||
zap.String("user_id", user.ID),
|
||||
zap.Error(err),
|
||||
)
|
||||
continue
|
||||
}
|
||||
deletedCount++
|
||||
}
|
||||
|
||||
log.Printf("[AccountCleanup] cleaned up %d expired accounts", deletedCount)
|
||||
zap.L().Info("Cleaned up expired accounts",
|
||||
zap.Int64("count", deletedCount),
|
||||
)
|
||||
return deletedCount, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user