Remove dead task DB fast-path and update task tests

This commit is contained in:
2026-04-07 20:00:13 +02:00
parent 0a70e40d8b
commit e21f153946
9 changed files with 96 additions and 25 deletions

View File

@@ -13,6 +13,7 @@ existing entry without creating duplicates.
from __future__ import annotations
import inspect
from typing import TYPE_CHECKING, Any
import structlog
@@ -34,10 +35,6 @@ JOB_ID: str = "blocklist_import"
async def _get_db(app: Any) -> tuple[aiosqlite.Connection, bool]:
existing_db = getattr(app.state, "db", None)
if existing_db is not None:
return existing_db, False
db = await open_db(app.state.settings.database_path)
return db, True
@@ -102,12 +99,16 @@ def register(app: FastAPI) -> None:
# APScheduler is synchronous at registration time; use asyncio to read
# the stored schedule from the DB before registering.
coro = None
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(_do_register())
coro = _do_register()
loop.run_until_complete(coro)
except RuntimeError:
# If the current thread already has a running loop (uvicorn), schedule
# the registration as a coroutine.
if coro is not None and inspect.getcoroutinestate(coro) != inspect.CORO_CLOSED:
coro.close()
asyncio.ensure_future(_do_register())

View File

@@ -34,10 +34,6 @@ JOB_ID: str = "geo_cache_flush"
async def _get_db(app: Any) -> tuple[aiosqlite.Connection, bool]:
existing_db = getattr(app.state, "db", None)
if existing_db is not None:
return existing_db, False
db = await open_db(app.state.settings.database_path)
return db, True

View File

@@ -40,10 +40,6 @@ JOB_ID: str = "geo_re_resolve"
async def _get_db(app: FastAPI) -> tuple[aiosqlite.Connection, bool]:
existing_db = getattr(app.state, "db", None)
if existing_db is not None:
return existing_db, False
db = await open_db(app.state.settings.database_path)
return db, True

View File

@@ -34,10 +34,6 @@ BACKFILL_WINDOW: int = 648000
async def _get_db(app: FastAPI) -> tuple[aiosqlite.Connection, bool]:
existing_db = getattr(app.state, "db", None)
if existing_db is not None:
return existing_db, False
db = await open_db(app.state.settings.database_path)
return db, True