From c3f8d64f0e8baf4c993f30f888dfd11db3ce92dd Mon Sep 17 00:00:00 2001 From: RRRosmontis Date: Wed, 23 Sep 2026 12:03:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(dufe):=20auto=20=E6=A8=A1=E5=BC=8F=20attem?= =?UTF-8?q?pts=20=E6=94=B9=E4=B8=BA=E9=80=90=E6=AC=A1=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - entry.attempts 由计数改为列表: 每次尝试 {n, success, message} - relogin 后立即重试的那次带 "relogin": true 标记 - 成功/失败(重试用尽)两种情况都完整携带全部尝试记录 --- .../dufe/ginkgostu_sign_in/ginkgo_sign_in.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/source/dufe/ginkgostu_sign_in/ginkgo_sign_in.py b/source/dufe/ginkgostu_sign_in/ginkgo_sign_in.py index 5e8fd38..c7e45d3 100644 --- a/source/dufe/ginkgostu_sign_in/ginkgo_sign_in.py +++ b/source/dufe/ginkgostu_sign_in/ginkgo_sign_in.py @@ -848,7 +848,8 @@ def _signin_one_with_retry(username, password, row, sess, token): token 疑似失效(上游错误/登录错)时重新登录一次后立即重试(对齐 bot refresh 语义)。 与 bot complete_signin 一致:除限流(外层中断)外,任何未确认成功都消耗重试次数; - 重试用尽记最终失败。返回 (entry, sess, token)。""" + 重试用尽记最终失败。entry["attempts"] 为逐次完整记录列表(每次的结果与原因, + relogin 后立即重试的那次带 "relogin": true)。返回 (entry, sess, token)。""" link = row["link"] base = { "activityKey": row.get("signin_activity_key"), @@ -859,16 +860,25 @@ def _signin_one_with_retry(username, password, row, sess, token): } attempts = 0 refreshed = False + relogin_before_next = False # 上一次迭代发生了重登录,下一次尝试标记 relogin last_err = "unknown error" last_data = None + attempt_log = [] # 逐次记录:{"n", "success", "message"[, "relogin"]} while attempts < MAX_SIGNIN_ATTEMPTS: attempts += 1 + record = {"n": attempts} + if relogin_before_next: + record["relogin"] = True + relogin_before_next = False try: data = fetch_sign_in_info(username, password, link, do_commit=True, sess=sess, token=token) last_data = data commit = data.get("commit") if isinstance(commit, dict) and commit.get("success") is True: + record["success"] = True + record["message"] = "签到成功" + attempt_log.append(record) entry = dict(base) entry.update({ "type": data.get("type"), @@ -878,12 +888,14 @@ def _signin_one_with_retry(username, password, row, sess, token): "status": data.get("status"), "success": True, "message": "签到成功", - "attempts": attempts, + "attempts": attempt_log, }) return entry, sess, token message = ((commit or {}).get("message") or "no commit result returned") last_err = str(message) + record["success"] = False + record["message"] = last_err except RateLimitedError: raise except (UpstreamError, AuthError) as e: @@ -892,14 +904,25 @@ def _signin_one_with_retry(username, password, row, sess, token): refreshed = True try: sess, token = login(username, password) + record["success"] = False + record["message"] = str(e) or type(e).__name__ + attempt_log.append(record) + relogin_before_next = True continue except Exception: pass # 重登录也失败:落入常规退避重试 last_err = str(e) or type(e).__name__ + record["success"] = False + record["message"] = last_err except NoSignInCodeError as e: last_err = str(e) + record["success"] = False + record["message"] = last_err except Exception as e: last_err = safe_error(e) + record["success"] = False + record["message"] = last_err + attempt_log.append(record) if attempts < MAX_SIGNIN_ATTEMPTS: time.sleep(SIGNIN_BACKOFF[min(attempts - 1, len(SIGNIN_BACKOFF) - 1)]) entry = dict(base) @@ -913,7 +936,7 @@ def _signin_one_with_retry(username, password, row, sess, token): }) entry.update({"success": False, "message": "签到失败(重试 %d 次): %s" % (attempts, last_err), - "attempts": attempts}) + "attempts": attempt_log}) return entry, sess, token