fix(drift_narrator): 補寫 narrative_text 到 DB + drift_repository.update_narrative
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user