diff --git a/services/migration_service/data/postgres_async_db.py b/services/migration_service/data/postgres_async_db.py index 9532bf65..b27812d0 100644 --- a/services/migration_service/data/postgres_async_db.py +++ b/services/migration_service/data/postgres_async_db.py @@ -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