44from fastapi import FastAPI
55
66from .._meta import APP_FINISHED_BANNER_MSG , APP_STARTED_BANNER_MSG
7- from ..db .events import close_db_connection , connect_to_db
7+ from ..db .events import (
8+ asyncpg_close_db_connection ,
9+ asyncpg_connect_to_db ,
10+ close_db_connection ,
11+ connect_to_db ,
12+ )
13+ from .settings import ApplicationSettings
814
915logger = logging .getLogger (__name__ )
1016
@@ -14,10 +20,12 @@ async def _on_startup() -> None:
1420 logger .info ("Application starting ..." )
1521 if app .state .settings .API_SERVER_POSTGRES :
1622 # database
23+ assert isinstance (app .state .settings , ApplicationSettings ) # nosec
1724 await connect_to_db (app )
25+ await asyncpg_connect_to_db (app , app .state .settings .API_SERVER_POSTGRES )
1826 assert app .state .engine # nosec
1927
20- print (APP_STARTED_BANNER_MSG , flush = True )
28+ print (APP_STARTED_BANNER_MSG , flush = True ) # noqa: T201
2129
2230 return _on_startup
2331
@@ -27,7 +35,9 @@ async def _on_shutdown() -> None:
2735 logger .info ("Application stopping, ..." )
2836
2937 if app .state .settings .API_SERVER_POSTGRES :
38+ assert isinstance (app .state .settings , ApplicationSettings ) # nosec
3039 try :
40+ await asyncpg_close_db_connection (app )
3141 await close_db_connection (app )
3242
3343 except Exception as err : # pylint: disable=broad-except
@@ -38,6 +48,6 @@ async def _on_shutdown() -> None:
3848 stack_info = app .state .settings .debug ,
3949 )
4050
41- print (APP_FINISHED_BANNER_MSG , flush = True )
51+ print (APP_FINISHED_BANNER_MSG , flush = True ) # noqa: T201
4252
4353 return _on_shutdown
0 commit comments