Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use latest fastapi event management api #298

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions server/src/curfu/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Provide FastAPI application and route declarations."""

from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
Expand Down Expand Up @@ -124,15 +127,15 @@ def get_domain_services() -> DomainService:
return domain_service


@app.on_event("startup")
async def startup() -> None:
"""Get FUSOR reference"""
@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()


@app.on_event("shutdown")
async def shutdown() -> None:
"""Clean up thread pool."""
yield
await app.state.fusor.cool_seq_tool.uta_db._connection_pool.close() # noqa: SLF001