fix(test1): X立即取样提示区分「今日已取样」与真无候选
当前在播房同日去重后返回 all_deduped,不再误报 no_candidates。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
708b2148bb
commit
0c3fc9f68e
@ -174,21 +174,42 @@ def sample_live_now() -> dict[str, Any]:
|
||||
settings = db.get_settings_map()
|
||||
if not settings.get("x_clips_enabled"):
|
||||
return {"enqueued": 0, "live_count": 0, "skipped_dedupe": 0, "job_ids": [], "reason": "x_clips_disabled"}
|
||||
# Manual sample must run even if periodic live_sample switch is off
|
||||
patched = {**settings, "x_clips_live_sample": True}
|
||||
rooms = db.list_live_douyin_rooms_for_shorts(limit=400)
|
||||
day = push_date_from_ts(time.time())
|
||||
skipped = 0
|
||||
eligible = 0
|
||||
any_live = bool(patched.get("x_clips_sample_any_live", True))
|
||||
for room in rooms:
|
||||
rid = str(room.get("room_id") or "")
|
||||
if rid and x_clips_db.has_x_clip_job_for_room_day(rid, day):
|
||||
if not rid:
|
||||
continue
|
||||
if patched.get("x_clips_dedupe_room_day", True) and x_clips_db.has_x_clip_job_for_room_day(rid, day):
|
||||
skipped += 1
|
||||
n = try_sample_live_rooms(settings)
|
||||
continue
|
||||
if any_live or _room_eligible(room, patched):
|
||||
eligible += 1
|
||||
n = try_sample_live_rooms(patched)
|
||||
jobs = x_clips_db.list_pending_x_clip_jobs(limit=20)
|
||||
reason = ""
|
||||
if n:
|
||||
reason = ""
|
||||
elif x_clips_db.x_clips_quota_gap(cfg=patched) <= 0:
|
||||
reason = "no_quota"
|
||||
elif skipped and skipped >= len(rooms) and len(rooms) > 0:
|
||||
reason = "all_deduped"
|
||||
elif eligible <= 0:
|
||||
reason = "no_candidates"
|
||||
else:
|
||||
reason = "enqueue_failed"
|
||||
return {
|
||||
"enqueued": n,
|
||||
"live_count": len(rooms),
|
||||
"skipped_dedupe": skipped,
|
||||
"eligible": eligible,
|
||||
"job_ids": [str(j.get("id")) for j in jobs],
|
||||
"reason": "" if n else ("no_quota" if x_clips_db.x_clips_quota_gap(cfg=settings) <= 0 else "no_candidates"),
|
||||
"reason": reason,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -282,7 +282,18 @@ export function ClipsPanel({
|
||||
onClick={() =>
|
||||
void run(async () => {
|
||||
const r = await fetchJson("/api/x-clips/sample-now", { method: "POST" });
|
||||
if (!r?.enqueued) throw new Error(r?.reason || "未入队(可能无在播或配额满)");
|
||||
const enq = Number(r?.enqueued || 0);
|
||||
if (enq > 0) return;
|
||||
const reason = String(r?.reason || "");
|
||||
const live = Number(r?.live_count || 0);
|
||||
const skip = Number(r?.skipped_dedupe || 0);
|
||||
if (reason === "all_deduped") {
|
||||
throw new Error(`今日在播房间都已取样过(${skip}/${live}),同房同日不重复`);
|
||||
}
|
||||
if (reason === "no_quota") throw new Error("今日配额已满");
|
||||
if (reason === "x_clips_disabled") throw new Error("请先开启自动切片");
|
||||
if (reason === "no_candidates") throw new Error(`无可用在播房间(在播 ${live})`);
|
||||
throw new Error(reason || "未入队");
|
||||
}, "取样完成")
|
||||
}
|
||||
>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user