feat(insta): _bg_extract uses preferences + 09:00 trends_collect cron

This commit is contained in:
2026-05-16 17:58:52 +09:00
parent 86694ae4fe
commit 42bd53ee7b
2 changed files with 15 additions and 3 deletions

View File

@@ -99,11 +99,16 @@ class ExtractRequest(BaseModel):
categories: Optional[list[str]] = None
async def _bg_extract(task_id: str, categories: list[str]):
async def _bg_extract(task_id: str, categories: Optional[list[str]] = None):
try:
db.update_task(task_id, "processing", 10, "추출 중")
for cat in categories:
keyword_extractor.extract_for_category(cat, limit=KEYWORDS_PER_CATEGORY)
prefs_rows = db.get_preferences()
weights = {p["category"]: p["weight"] for p in prefs_rows}
if categories:
# 사용자가 카테고리 명시한 경우만 그 서브셋으로 균등 가중치 (override)
weights = {c: 1.0 for c in categories}
total = KEYWORDS_PER_CATEGORY * max(1, len([w for w in weights.values() if w > 0]))
keyword_extractor.extract_with_weights(weights, total_limit=total)
db.update_task(task_id, "succeeded", 100, "완료", result_id=0)
except Exception as e:
logger.exception("extract failed")