for AsyncEngine created in function scope, close and clean-up pooled connections adding await engine.dispose()

This commit is contained in:
kuba
2022-02-02 12:55:26 +01:00
parent f505a1eb05
commit 9b34191069
7 changed files with 29 additions and 38 deletions

View File

@@ -31,9 +31,7 @@ class Settings(BaseSettings):
pg_pass: str = os.getenv("POSTGRES_PASSWORD", "")
pg_host: str = os.getenv("SQL_HOST", "")
pg_database: str = os.getenv("SQL_DB", "")
pg_test_database: str = os.getenv("SQL_TEST_DB", "")
asyncpg_url: str = f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}"
asyncpg_test_url: str = f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_test_database}"
jwt_secret_key: str = os.getenv("SECRET_KEY", "")
jwt_algorithm: str = os.getenv("ALGORITHM", "")

View File

@@ -31,3 +31,6 @@ async def get_db() -> AsyncGenerator:
raise ex
finally:
await session.close()
# for AsyncEngine created in function scope, close and
# clean-up pooled connections
await engine.dispose()