From ce5138ba8e98bafd777504b11f9fa43fdaab57d4 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Mon, 5 Aug 2024 14:21:05 -0400 Subject: [PATCH] commit this --- server/src/curfu/main.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/server/src/curfu/main.py b/server/src/curfu/main.py index 0f5df845..3a7734d9 100644 --- a/server/src/curfu/main.py +++ b/server/src/curfu/main.py @@ -25,6 +25,21 @@ validate, ) + +@asynccontextmanager +async def lifespan(app: FastAPI) -> AsyncGenerator: + """Configure FastAPI instance lifespan. + + :param app: FastAPI app instance + :return: async context handler + """ + app.state.fusor = await start_fusor() + app.state.genes = get_gene_services() + app.state.domains = get_domain_services() + yield + await app.state.fusor.cool_seq_tool.uta_db._connection_pool.close() # noqa: SLF001 + + fastapi_app = FastAPI( title="Fusion Curation API", description="Provide data functions to support [VICC Fusion Curation interface](fusion-builder.cancervariants.org/).", @@ -41,6 +56,7 @@ swagger_ui_parameters={"tryItOutEnabled": True}, docs_url="/docs", openapi_url="/openapi.json", + lifespan=lifespan, ) fastapi_app.include_router(utilities.router) @@ -125,17 +141,3 @@ def get_domain_services() -> DomainService: domain_service = DomainService() domain_service.load_mapping() return domain_service - - -@asynccontextmanager -async def lifespan(app: FastAPI) -> AsyncGenerator: - """Configure FastAPI instance lifespan. - - :param app: FastAPI app instance - :return: async context handler - """ - app.state.fusor = await start_fusor() - app.state.genes = get_gene_services() - app.state.domains = get_domain_services() - yield - await app.state.fusor.cool_seq_tool.uta_db._connection_pool.close() # noqa: SLF001