Move runtime application state into a dedicated runtime state manager
This commit is contained in:
@@ -45,6 +45,7 @@ from app.routers import (
|
||||
)
|
||||
from app.startup import startup_shared_resources
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError, Fail2BanProtocolError
|
||||
from app.utils.runtime_state import ApplicationState, RuntimeState
|
||||
from app.utils.setup_state import is_setup_complete_cached, set_setup_complete_cache
|
||||
|
||||
log: structlog.stdlib.BoundLogger = structlog.get_logger()
|
||||
@@ -283,7 +284,10 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
lifespan=_lifespan,
|
||||
)
|
||||
|
||||
# Store settings on app.state so the lifespan handler can access them.
|
||||
# Store immutable configuration and the dedicated runtime state manager on
|
||||
# app.state. Runtime state values are proxied through the wrapper so the
|
||||
# shared Starlette state bag itself does not hold mutable business state.
|
||||
app.state = ApplicationState(RuntimeState())
|
||||
app.state.settings = resolved_settings
|
||||
set_setup_complete_cache(app, False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user