Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Mar 7, 2022
1 parent dd8209a commit 259e0c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/settings-library/src/settings_library/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def dsn(self) -> str:
)
return dsn

@cached_property
def dsn_with_async_sqlalchemy(self) -> str:
dsn = self.dsn.replace("postgresql", "postgresql+asyncpg")
return dsn

@cached_property
def dsn_with_query(self) -> str:
"""Some clients do not support queries in the dsn"""
Expand Down
11 changes: 5 additions & 6 deletions services/catalog/src/simcore_service_catalog/db/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
async def connect_to_db(app: FastAPI) -> None:
logger.debug("Connecting db ...")
cfg: PostgresSettings = app.state.settings.CATALOG_POSTGRES
logger.debug(cfg.dsn)
modified_dsn = cfg.dsn.replace("postgresql", "postgresql+asyncpg")
logger.debug(modified_dsn)

engine: AsyncEngine = create_async_engine(
modified_dsn,
cfg.dsn_with_async_sqlalchemy,
pool_size=cfg.POSTGRES_MINSIZE,
max_overflow=cfg.POSTGRES_MAXSIZE - cfg.POSTGRES_MINSIZE,
connect_args={
"server_settings": {"application_name": cfg.POSTGRES_CLIENT_NAME}
},
echo=True,
)
logger.debug("Connected to %s", cfg.dsn)

logger.debug("Connected to %s", engine.url) # pylint: disable=no-member

logger.debug("Checking db migration...")
try:
Expand All @@ -56,4 +55,4 @@ async def close_db_connection(app: FastAPI) -> None:
if engine := app.state.engine:
await close_engine(engine)

logger.debug("Disconnected from %s", engine.url)
logger.debug("Disconnected from %s", engine.url) # pylint: disable=no-member

0 comments on commit 259e0c2

Please sign in to comment.