fix using deprecated Starlette feature

`on_startup`/`on_shutdown` will be removed in v1.0.
This commit is contained in:
ducklet 2023-03-18 00:09:58 +01:00
parent 5efa3ef2c2
commit eb76ab1867

View file

@ -1,4 +1,5 @@
import asyncio
import contextlib
import logging
import secrets
from json.decoder import JSONDecodeError
@ -612,6 +613,13 @@ def auth_error(request, err):
return unauthorized(str(err))
@contextlib.asynccontextmanager
async def lifespan(app: Starlette):
await open_connection_pool()
yield
await close_connection_pool()
def create_app():
if config.loglevel == "DEBUG":
logging.basicConfig(
@ -622,8 +630,7 @@ def create_app():
log.debug(f"Log level: {config.loglevel}")
return Starlette(
on_startup=[open_connection_pool],
on_shutdown=[close_connection_pool],
lifespan=lifespan,
routes=[
Mount(f"{config.api_base}v1", routes=route.registered),
],