fix(drift_narrator): 補寫 narrative_text 到 DB + drift_repository.update_narrative
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled

This commit is contained in:
OG T
2026-04-10 11:06:50 +08:00
parent c6edfb5614
commit b24fae313e
2 changed files with 16 additions and 0 deletions

View File

@@ -154,6 +154,15 @@ class DriftReportRepository:
)
async def update_narrative(self, report_id: str, narrative: str) -> None:
"""更新 AI 人話摘要 (Phase 30 ADR-067)"""
async with get_db_context() as db:
await db.execute(
text("UPDATE drift_reports SET narrative_text = :narrative WHERE report_id = :report_id"),
{"report_id": report_id, "narrative": narrative},
)
_drift_repo: DriftReportRepository | None = None

View File

@@ -112,6 +112,13 @@ class DriftNarratorService:
narrative = await self._generate_narrative(report, interpretation)
await self._send_telegram(report, narrative)
# 寫入 DB narrative_text (Phase 30 ADR-067)
try:
from src.repositories.drift_repository import get_drift_repository
await get_drift_repository().update_narrative(report.report_id, narrative)
except Exception as e:
logger.warning("drift_narrator_db_write_failed", error=str(e))
# 寫入快取
await redis.set(cache_key, narrative[:500], ex=CACHE_TTL)