Complete Task 11 by moving history_archive_repo import to history_sync top-level
This commit is contained in:
@@ -317,6 +317,8 @@ Deferred function-body imports hide module-level code dependencies, break standa
|
|||||||
|
|
||||||
### Task 11 — Replace history_sync.py deferred import inside loop
|
### Task 11 — Replace history_sync.py deferred import inside loop
|
||||||
|
|
||||||
|
**Status:** Completed
|
||||||
|
|
||||||
**Severity:** Medium
|
**Severity:** Medium
|
||||||
|
|
||||||
**Where:**
|
**Where:**
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ from __future__ import annotations
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
import aiosqlite
|
|
||||||
from app.config import Settings
|
|
||||||
|
|
||||||
import structlog
|
import structlog
|
||||||
|
|
||||||
from app.db import open_db
|
from app.db import open_db
|
||||||
from app.repositories import fail2ban_db_repo
|
from app.repositories import fail2ban_db_repo
|
||||||
|
from app.repositories.history_archive_repo import archive_ban_event
|
||||||
from app.utils.fail2ban_db_utils import get_fail2ban_db_path
|
from app.utils.fail2ban_db_utils import get_fail2ban_db_path
|
||||||
from app.utils.runtime_state import get_effective_settings
|
from app.utils.runtime_state import get_effective_settings
|
||||||
|
|
||||||
if TYPE_CHECKING: # pragma: no cover
|
if TYPE_CHECKING:
|
||||||
|
import aiosqlite
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
from app.config import Settings
|
||||||
|
|
||||||
log: structlog.stdlib.BoundLogger = structlog.get_logger()
|
log: structlog.stdlib.BoundLogger = structlog.get_logger()
|
||||||
|
|
||||||
#: Stable APScheduler job id.
|
#: Stable APScheduler job id.
|
||||||
@@ -35,7 +35,7 @@ HISTORY_SYNC_INTERVAL: int = 300
|
|||||||
BACKFILL_WINDOW: int = 648000
|
BACKFILL_WINDOW: int = 648000
|
||||||
|
|
||||||
|
|
||||||
async def _get_db(settings: "Settings") -> tuple[aiosqlite.Connection, bool]:
|
async def _get_db(settings: Settings) -> tuple[aiosqlite.Connection, bool]:
|
||||||
db = await open_db(settings.database_path)
|
db = await open_db(settings.database_path)
|
||||||
return db, True
|
return db, True
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ async def _get_last_archive_ts(db) -> int | None:
|
|||||||
return int(row[0])
|
return int(row[0])
|
||||||
|
|
||||||
|
|
||||||
async def _run_sync_with_settings(settings: "Settings") -> None:
|
async def _run_sync_with_settings(settings: Settings) -> None:
|
||||||
socket_path: str = settings.fail2ban_socket
|
socket_path: str = settings.fail2ban_socket
|
||||||
db, close_db = await _get_db(settings)
|
db, close_db = await _get_db(settings)
|
||||||
|
|
||||||
@@ -76,8 +76,6 @@ async def _run_sync_with_settings(settings: "Settings") -> None:
|
|||||||
if not rows:
|
if not rows:
|
||||||
break
|
break
|
||||||
|
|
||||||
from app.repositories.history_archive_repo import archive_ban_event
|
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
await archive_ban_event(
|
await archive_ban_event(
|
||||||
db=db,
|
db=db,
|
||||||
|
|||||||
Reference in New Issue
Block a user