diff options
Diffstat (limited to 'database.py')
| -rw-r--r-- | database.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/database.py b/database.py index 0679a52..45467f6 100644 --- a/database.py +++ b/database.py @@ -10,13 +10,24 @@ class Database(object): def __init__(self): self._pool = None - async def connect(self, connstring): + async def connect(self, host, port, user, password, database): """Connects to the database. :param connstring: Connection string containing user and database. :type connstring: str """ - self._pool = await asyncpg.create_pool(connstring) + while True: # retry until connection succeeds + try: + print("attempting to connect to db…") + self._pool = await asyncpg.create_pool( + host=host, port=port, user=user, + password=password, database=database) + break + except asyncpg.exceptions.CannotConnectNowError: + await self._pool.close() + print("Database is not ready yet. Retrying…") + await asyncio.sleep(5) + async def upsert_type(self, obj, objtype, many=False): """Upserts an object of given `objtype` into the corresponding database. |
