Skip to content

Commit

Permalink
increases db timeout and allow context reentry
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBarberini committed Jun 13, 2024
1 parent 44493aa commit 9cf049e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/repositories/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __new__(cls, *args, **kwargs):
return cls._instances[cls]

def __init__(self, collection_name: str):
self._entered = False
if not getattr(self, '_initialized', False):
self._collection_name = collection_name
self._initialized_event = asyncio.Event()
Expand All @@ -45,7 +46,8 @@ async def _async_init(self):
self._initialized_event.set()

async def __aenter__(self):
await self._initialized_event.wait()
if not self._entered:
await self._initialized_event.wait()
return self

async def __aexit__(self, exc_type, exc_value, traceback):
Expand All @@ -63,7 +65,7 @@ def _initialize_connection(self):
server_api=ServerApi("1"),
maxIdleTimeMS=5000,
connectTimeoutMS=5000,
serverSelectionTimeoutMS=15000,
serverSelectionTimeoutMS=30000,
)
self._collection = self._client.rocketpy[self._collection_name]
logger.info("MongoDB client initialized for %s", self.__class__)
Expand Down

0 comments on commit 9cf049e

Please sign in to comment.