Convert setup guard to startup-driven cache and update tests
This commit is contained in:
24
backend/app/utils/setup_state.py
Normal file
24
backend/app/utils/setup_state.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Manage the cached setup completion flag stored on application state."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def invalidate_setup_complete_cache(app: FastAPI) -> None:
|
||||
"""Reset the cached setup completion state.
|
||||
|
||||
This helper exists so the cache can be invalidated explicitly if the
|
||||
application state changes during runtime.
|
||||
"""
|
||||
app.state.setup_complete_cached = False
|
||||
Reference in New Issue
Block a user