优化全能创作

This commit is contained in:
Azmat@qq.com
2026-09-11 19:11:27 +08:00
parent dbcac8a44b
commit 02e5dbfb60
25 changed files with 2398 additions and 462 deletions
+25
View File
@@ -4,6 +4,7 @@
全部 best-effort:审核未启用/出错都不影响主流程(生图/采用照常)。
"""
import logging
import time
from datetime import timedelta
from django.db import IntegrityError, transaction
@@ -233,6 +234,30 @@ def ensure_review_drain_loop() -> None:
logger.warning("kick asset review drain loop failed", exc_info=True)
def wait_upload_review(asset: Asset, *, timeout_s: float = 45.0, interval_s: float = 1.5) -> str:
"""上传素材:立刻送审并等到终态。
返回 active / failed / processing(超时仍在审) / allowed(审核未启用)。
审核未配置时不能拦上传,直接当 allowed。
"""
if not assets_client.is_enabled():
return "allowed"
submit_asset_for_review(asset, force=True)
asset.refresh_from_db()
status = asset.review_status or ""
if status in ("active", "failed"):
return status
deadline = time.monotonic() + max(3.0, float(timeout_s))
while time.monotonic() < deadline:
status = poll_asset_review(asset) or ""
if status in ("active", "failed"):
return status
time.sleep(max(0.4, float(interval_s)))
asset.refresh_from_db()
return asset.review_status or "processing"
def poll_asset_review(asset: Asset) -> str:
"""查单个真人资产审核状态并更新 review_status。返回最新状态。
只在状态变化时落库(保留 updated_at 作为「进入 processing 的时刻」);processing 超时兜底为 failed。"""