From dd2931af865ce3d835584756a7122d096db9f7d5 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 19 Aug 2026 08:40:38 -0500 Subject: [PATCH] =?UTF-8?q?fix(test1):=20X=20=E5=88=87=E7=89=87=E6=97=A0?= =?UTF-8?q?=E9=99=90=E9=87=8D=E5=8F=91=20bug=20=E2=80=94=20reclaim=20?= =?UTF-8?q?=E6=8A=8A=E5=B7=B2=E5=AE=8C=E6=88=90=E4=BB=BB=E5=8A=A1=E9=80=80?= =?UTF-8?q?=E5=9B=9E=20scheduled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:postTweet 不返回 tweetId,sync 写空 tweet_id,reclaim 又退回。 修复:1) tweet_id 为空时用 x2:jobId 标记已完成 2) reclaim 排除 finished_at>0 3) attempts>=3 直接 failed 不再循环。 Co-authored-by: Cursor --- backend/app/x_clips_db.py | 19 +++++++++++++++++-- backend/app/x_clips_pipeline.py | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/app/x_clips_db.py b/backend/app/x_clips_db.py index 326c100..81bedcf 100644 --- a/backend/app/x_clips_db.py +++ b/backend/app/x_clips_db.py @@ -440,12 +440,25 @@ def reclaim_stale_x_clip_recordings(*, max_age_sec: float = 240) -> int: conn.close() -def reclaim_stale_x_clip_posts(*, max_age_sec: float = 900) -> int: +def reclaim_stale_x_clip_posts(*, max_age_sec: float = 900, max_attempts: int = 3) -> int: cutoff = time.time() - max(120.0, float(max_age_sec)) + now = time.time() with _lock: conn = _connect() try: ensure_x_clips_tables(conn) + # Fail jobs that exceeded retry limit + conn.execute( + """ + UPDATE x_clip_jobs + SET status = 'failed', error = '超过最大重试次数', updated_at = ?, finished_at = ? + WHERE status = 'posting' AND updated_at < ? + AND IFNULL(tweet_id, '') = '' + AND IFNULL(finished_at, 0) = 0 + AND attempts >= ? + """, + (now, now, cutoff, max(1, int(max_attempts))), + ) cur = conn.execute( """ UPDATE x_clip_jobs @@ -453,8 +466,10 @@ def reclaim_stale_x_clip_posts(*, max_age_sec: float = 900) -> int: x2_job_id = '', media_key = CASE WHEN media_url != '' THEN media_key ELSE '' END WHERE status = 'posting' AND updated_at < ? AND IFNULL(tweet_id, '') = '' + AND IFNULL(finished_at, 0) = 0 + AND attempts < ? """, - (time.time(), cutoff), + (now, cutoff, max(1, int(max_attempts))), ) conn.commit() return int(cur.rowcount or 0) diff --git a/backend/app/x_clips_pipeline.py b/backend/app/x_clips_pipeline.py index 183a5da..9cb9938 100644 --- a/backend/app/x_clips_pipeline.py +++ b/backend/app/x_clips_pipeline.py @@ -605,6 +605,10 @@ class XClipsPipeline: or result.get("id") or "" ).strip() + # Extension postTweet does not return tweetId; use x2 job id + # as proof of completion to prevent reclaim loop. + if not tweet_id: + tweet_id = f"x2:{x2_id}" x_clips_db.update_x_clip_job( jid, status="posted",