refactor(fc2c-i): sweep blueprints + ml tasks onto shared get_session (covers tasks/ml.py, a survey gap)

This commit is contained in:
2026-05-15 15:48:02 -04:00
parent fc33c23dd5
commit f7f75fcac6
9 changed files with 42 additions and 164 deletions
+4 -8
View File
@@ -305,13 +305,11 @@ def _confidence_for_tag(session, tag, preds: dict) -> float | None:
def recompute_centroid(self, tag_id: int) -> bool:
import asyncio
from ..extensions import make_engine, make_session_factory
from ..extensions import get_session
from ..services.ml.centroids import CentroidService
async def _run() -> bool:
engine = make_engine()
Session = make_session_factory(engine)
async with Session() as session:
async with get_session() as session:
svc = CentroidService(session)
result = await svc.recompute_for_tag(tag_id)
await session.commit()
@@ -325,13 +323,11 @@ def recompute_centroids(self) -> int:
"""Daily: find drifted centroids, enqueue recompute_centroid for each."""
import asyncio
from ..extensions import make_engine, make_session_factory
from ..extensions import get_session
from ..services.ml.centroids import CentroidService
async def _list() -> list[int]:
engine = make_engine()
Session = make_session_factory(engine)
async with Session() as session:
async with get_session() as session:
return await CentroidService(session).list_drifted()
drifted = asyncio.run(_list())