Skip to content

Commit

Permalink
Only create Manager() if we are not going to use Redis for PubSub
Browse files Browse the repository at this point in the history
  • Loading branch information
AliRn76 committed Jan 24, 2024
1 parent 52ad77a commit 192f8a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/core/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{'url': f'pantherdb://{BASE_DIR}/{DB_NAME}.pdb'},
),
# ('panther.middlewares.db.DatabaseMiddleware', {'url': f'mongodb://{DB_HOST}:27017/{DB_NAME}'}),
# ('panther.middlewares.redis.RedisMiddleware', {'host': '127.0.0.1', 'port': 6379}),
('panther.middlewares.redis.RedisMiddleware', {'host': '127.0.0.1', 'port': 6379}),
]
"""
mongodb://[Username:Password(optional)]@HostName:Port/?aruguments
Expand Down
2 changes: 1 addition & 1 deletion panther/base_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def publish(self, msg):


class WebsocketConnections(Singleton):
def __init__(self, manager: Manager):
def __init__(self, manager: Manager = None):
self.connections = {}
self.connections_count = 0
self.manager = manager
Expand Down
5 changes: 4 additions & 1 deletion panther/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def _create_ws_connections_instance(self):

# Create websocket connections instance
if config['has_ws']:
config['websocket_connections'] = WebsocketConnections(manager=Manager())
# Websocket Redis Connection
for middleware in config['http_middlewares']:
if middleware.__class__.__name__ == 'RedisMiddleware':
Expand All @@ -112,6 +111,10 @@ def _create_ws_connections_instance(self):
else:
self.ws_redis_connection = None

# Don't create Manager() if we are going to use Redis for PubSub
manager = None if self.ws_redis_connection else Manager()
config['websocket_connections'] = WebsocketConnections(manager=manager)

async def __call__(self, scope: dict, receive: Callable, send: Callable) -> None:
"""
1.
Expand Down

0 comments on commit 192f8a9

Please sign in to comment.