Skip to content

Commit

Permalink
Fix AsyncPostgresDB initialization retry logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
fumoboy007 committed Sep 9, 2024
1 parent d24ee48 commit 624d16d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions services/migration_service/data/postgres_async_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ def __init__(self):
AsyncPostgresDB.__instance = self

async def _init(self, db_conf: DBConfiguration):
# todo make poolsize min and max configurable as well as timeout
# todo add retry and better error message
retries = 3
for i in range(retries):
# todo make poolsize min and max configurable
max_attempts = 3
while max_attempts > 0:
try:
self.pool = await aiopg.create_pool(db_conf.get_dsn(), timeout=db_conf.timeout)
break
except Exception as e:
print("printing connection exception: " + str(e))
if retries - i < 1:

max_attempts -= 1
if max_attempts == 0:
raise e

time.sleep(1)
continue

0 comments on commit 624d16d

Please sign in to comment.