Move runtime application state into a dedicated runtime state manager

This commit is contained in:
2026-04-10 19:07:35 +02:00
parent 6b177f1881
commit ff92733f90
6 changed files with 223 additions and 55 deletions

View File

@@ -2,17 +2,22 @@
from __future__ import annotations
from fastapi import FastAPI
from typing import TYPE_CHECKING
from app.utils.runtime_state import get_runtime_state
if TYPE_CHECKING: # pragma: no cover
from fastapi import FastAPI
def is_setup_complete_cached(app: FastAPI) -> bool:
"""Return the cached setup completion state from application state."""
return getattr(app.state, "setup_complete_cached", False)
"""Return the cached setup completion state from the runtime state manager."""
return get_runtime_state(app).setup_complete_cached
def set_setup_complete_cache(app: FastAPI, completed: bool) -> None:
"""Set the cached setup completion state on application state."""
app.state.setup_complete_cached = completed
"""Set the cached setup completion state on the runtime state manager."""
get_runtime_state(app).setup_complete_cached = completed
def invalidate_setup_complete_cache(app: FastAPI) -> None:
@@ -21,4 +26,4 @@ def invalidate_setup_complete_cache(app: FastAPI) -> None:
This helper exists so the cache can be invalidated explicitly if the
application state changes during runtime.
"""
app.state.setup_complete_cached = False
get_runtime_state(app).setup_complete_cached = False