- A1: fire the hard filter (Apify is precise); embedding vibe-ranker (embed.py) blends with the floor-free white-box (rank.py) to sift ~90 -> top 18 - A2: Opus curator (curate.py) reads the 18 -> honest <=count + Gemini-voiced report cards; graceful fallback to the white-box + templated cards - LLM via opencode.ai/zen gateway (llm.py): Opus chat + direct-OpenAI embeddings - Run LLM work off the event loop (asyncio.to_thread) so the Redis response publishes - C1: dedicated Postgres (app/db/) persists the per-user feed; get_scout_feed replays it so matches survive navigation/refresh - match contract + report-card fields (schema.py); skills.py; tests/
38 lines
983 B
Python
38 lines
983 B
Python
"""Async SQLAlchemy engine + session factory (mirrors qscore-service/app/db/session.py).
|
|
|
|
Lazily built so the service boots even when no DB is configured — `engine()` returns None then,
|
|
and every caller treats that as "persistence off".
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from functools import lru_cache
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from app.config import get_settings
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@lru_cache
|
|
def _engine_and_factory():
|
|
s = get_settings()
|
|
if not s.DATABASE_URL:
|
|
return None, None
|
|
eng = create_async_engine(s.DATABASE_URL, pool_pre_ping=True, pool_size=5, max_overflow=10)
|
|
factory = async_sessionmaker(eng, class_=AsyncSession, expire_on_commit=False)
|
|
return eng, factory
|
|
|
|
|
|
def engine():
|
|
return _engine_and_factory()[0]
|
|
|
|
|
|
def session_factory():
|
|
return _engine_and_factory()[1]
|
|
|
|
|
|
def db_enabled() -> bool:
|
|
return engine() is not None
|