Remove dead task DB fast-path and update task tests
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user