fix using deprecated Starlette feature
`on_startup`/`on_shutdown` will be removed in v1.0.
This commit is contained in:
parent
5efa3ef2c2
commit
eb76ab1867
1 changed files with 9 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
import secrets
|
import secrets
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
|
|
@ -612,6 +613,13 @@ def auth_error(request, err):
|
||||||
return unauthorized(str(err))
|
return unauthorized(str(err))
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.asynccontextmanager
|
||||||
|
async def lifespan(app: Starlette):
|
||||||
|
await open_connection_pool()
|
||||||
|
yield
|
||||||
|
await close_connection_pool()
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
if config.loglevel == "DEBUG":
|
if config.loglevel == "DEBUG":
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|
@ -622,8 +630,7 @@ def create_app():
|
||||||
log.debug(f"Log level: {config.loglevel}")
|
log.debug(f"Log level: {config.loglevel}")
|
||||||
|
|
||||||
return Starlette(
|
return Starlette(
|
||||||
on_startup=[open_connection_pool],
|
lifespan=lifespan,
|
||||||
on_shutdown=[close_connection_pool],
|
|
||||||
routes=[
|
routes=[
|
||||||
Mount(f"{config.api_base}v1", routes=route.registered),
|
Mount(f"{config.api_base}v1", routes=route.registered),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue