Skip to content

Commit

Permalink
Use lifespan instead of event handler to remove deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
augusto-herrmann committed Oct 4, 2024
1 parent fa7cf0c commit 14397c1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Definição das rotas, endpoints e seu comportamento na API.
"""

from contextlib import asynccontextmanager
from datetime import timedelta
import json
import os
Expand Down Expand Up @@ -42,20 +43,20 @@

description = environment_msg + description

@asynccontextmanager
async def lifespan(app: FastAPI):
"""Executa as rotinas de inicialização da API."""
await create_db_and_tables()
await crud_auth.init_user_admin()
yield

app = FastAPI(
title="Plataforma de recebimento de dados do Programa de Gestão - PGD",
description=description,
version=os.getenv("TAG_NAME", "dev-build") or "dev-build",
lifespan=lifespan,
)


@app.on_event("startup")
async def on_startup():
"""Executa as rotinas de inicialização da API."""
await create_db_and_tables()
await crud_auth.init_user_admin()


@app.middleware("http")
async def check_user_agent(request: Request, call_next):
user_agent = request.headers.get("User-Agent", None)
Expand Down

0 comments on commit 14397c1

Please sign in to comment.