bfddfdfdfewe
This commit is contained in:
@@ -404,18 +404,29 @@ async def enrichment_loop() -> None:
|
||||
while True:
|
||||
try:
|
||||
async with AsyncSessionLocal() as session:
|
||||
# 已翻译完成 + 4 个状态中至少有一个是 pending
|
||||
# 关键:不能按 translated_at 升序 — 老文章已 enrich,新文章 translated_at=NULL(被排到最后)
|
||||
# 改为按 id 升序(新文章 id 大),循环里再过滤 status
|
||||
# 精准定位待 enrich 的文章:已翻译 + 任一 LLM 状态 ∈ {n/a, pending, failed}
|
||||
# (不能用 order_by id ASC + 内存过滤:已 enrich 的文章 id 可能更小,会占满 limit,
|
||||
# 让 enrichment_loop 永远看不到后面大 id 的 n/a 文章 — 真实踩过的坑)
|
||||
rows = (
|
||||
await session.execute(
|
||||
select(Article)
|
||||
.where(
|
||||
Article.translation_status == "ok",
|
||||
Article.title_zh.is_not(None),
|
||||
# 任一 LLM 状态不是 ok(包括 NULL)
|
||||
(
|
||||
(Article.classify_status.is_(None))
|
||||
| (Article.classify_status != "ok")
|
||||
| (Article.format_status.is_(None))
|
||||
| (Article.format_status != "ok")
|
||||
| (Article.commentary_status.is_(None))
|
||||
| (Article.commentary_status != "ok")
|
||||
| (Article.image_ai_status.is_(None))
|
||||
| (Article.image_ai_status != "ok")
|
||||
),
|
||||
)
|
||||
.order_by(Article.id.asc())
|
||||
.limit(ENRICHMENT_BATCH_SIZE * 20) # 多取一些找需要 enrich 的
|
||||
.limit(ENRICHMENT_BATCH_SIZE * 5) # 比 batch 略多
|
||||
)
|
||||
).scalars()
|
||||
candidates = list(rows)
|
||||
|
||||
Reference in New Issue
Block a user