Debian Codegraph @

docs/examples/application_hooks/on_app_init.py

raw
1 from typing import TYPE_CHECKING
2
3 from litestar import Litestar
4
5 if TYPE_CHECKING:
6 from litestar.config.app import AppConfig
7
8
9 async def close_db_connection() -> None:
10 """Closes the database connection on application shutdown."""
11
12
13 def receive_app_config(app_config: "AppConfig") -> "AppConfig":
14 """Receives parameters from the application.
15
16 In reality, this would be a library of boilerplate that is carried from one application to another, or a third-party
17 developed application configuration tool.
18 """
19 app_config.on_shutdown.append(close_db_connection)
20 return app_config
21
22
23 app = Litestar([], on_app_init=[receive_app_config])