Skip to content

Commit

Permalink
Add retry loop for connecting to the database
Browse files Browse the repository at this point in the history
4Kaylum committed Nov 26, 2024
1 parent d1e06a0 commit 2ebc083
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions novus/ext/database/database.py
Original file line number Diff line number Diff line change
@@ -50,14 +50,17 @@ class Database(client.Plugin):
_pool_created: asyncio.Event | None = None

@classmethod
def acquire(cls, *args: Any, **kwargs: Any) -> PoolAcquireContext:
def acquire(cls, *args: Any, _attempt: int = 0, **kwargs: Any) -> PoolAcquireContext:
if cls.pool is None:
raise Exception(
(
"Database pool is not created - was the plugin loaded? "
"Was there a DSN provided?"
if _attempt >= 5:
raise Exception(
(
"Database pool is not created - was the plugin loaded? "
"Was there a DSN provided?"
)
)
)
else:
return cls.acquire(*args, _attempt=_attempt + 1, **kwargs)
return cls.pool.acquire(*args, **kwargs) # pyright: ignore

async def create_pool(

0 comments on commit 2ebc083

Please sign in to comment.