Mark startup runtime configuration task complete and update startup resource resolution

This commit is contained in:
2026-04-10 21:13:51 +02:00
parent f61d497e4e
commit 91e5792caf
3 changed files with 106 additions and 25 deletions

View File

@@ -9,13 +9,12 @@ from __future__ import annotations
from contextlib import suppress
from pathlib import Path
from typing import TYPE_CHECKING
import aiohttp
import structlog
from apscheduler.schedulers.asyncio import AsyncIOScheduler # type: ignore[import-untyped]
from fastapi import FastAPI
from app.config import Settings
from app.db import init_db, open_db
from app.services import geo_service, setup_service
from app.tasks import blocklist_import, geo_cache_flush, geo_re_resolve, health_check, history_sync
@@ -23,6 +22,11 @@ from app.utils.jail_config import ensure_jail_configs
from app.utils.runtime_state import set_runtime_settings
from app.utils.setup_state import set_setup_complete_cache
if TYPE_CHECKING:
from fastapi import FastAPI
from app.config import Settings
log: structlog.stdlib.BoundLogger = structlog.get_logger()
@@ -64,8 +68,6 @@ async def startup_shared_resources(
Returns:
A tuple of ``(http_session, scheduler)``.
"""
ensure_jail_configs(Path(settings.fail2ban_config_dir) / "jail.d")
db_path: Path = Path(settings.database_path)
db_path.parent.mkdir(parents=True, exist_ok=True)
@@ -75,8 +77,6 @@ async def startup_shared_resources(
startup_db = await open_db(settings.database_path)
try:
await init_db(startup_db)
await geo_service.load_cache_from_db(startup_db)
unresolved_count = await geo_service.count_unresolved(startup_db)
setup_complete = await setup_service.is_setup_complete(startup_db)
set_setup_complete_cache(app, setup_complete)
log.debug("setup_completion_cached", completed=setup_complete)
@@ -95,9 +95,22 @@ async def startup_shared_resources(
"runtime_settings_overridden_from_setup",
overrides=persisted_runtime_settings,
)
if Path(settings.database_path).resolve() != original_db_path:
runtime_db = await open_db(settings.database_path)
try:
await geo_service.load_cache_from_db(runtime_db)
unresolved_count = await geo_service.count_unresolved(runtime_db)
finally:
await runtime_db.close()
else:
await geo_service.load_cache_from_db(startup_db)
unresolved_count = await geo_service.count_unresolved(startup_db)
finally:
await startup_db.close()
ensure_jail_configs(Path(settings.fail2ban_config_dir) / "jail.d")
if unresolved_count > 0:
log.warning("geo_cache_unresolved_ips", unresolved=unresolved_count)