developmentseed/tipg

Update Lifespan event handler (and FastAPI version)

Closed this issue · 0 comments

new Fastapi https://fastapi.tiangolo.com/release-notes/#0940 introduced a new way to handle lifespan events

ref https://fastapi.tiangolo.com/advanced/events/#alternative-events-deprecated

tipg/tipg/main.py

Lines 65 to 86 in 41bb265

@app.on_event("startup")
async def startup_event() -> None:
"""Connect to database on startup."""
await connect_to_db(app, settings=postgres_settings)
await register_collection_catalog(
app,
schemas=db_settings.schemas,
exclude_schemas=db_settings.exclude_schemas,
tables=db_settings.tables,
exclude_tables=db_settings.exclude_tables,
function_schemas=db_settings.function_schemas,
exclude_function_schemas=db_settings.exclude_function_schemas,
functions=db_settings.functions,
exclude_functions=db_settings.exclude_functions,
spatial=db_settings.only_spatial_tables,
)
@app.on_event("shutdown")
async def shutdown_event() -> None:
"""Close database connection."""
await close_db_connection(app)