feat(dufe): auto 模式 attempts 改为逐次完整记录
- entry.attempts 由计数改为列表: 每次尝试 {n, success, message}
- relogin 后立即重试的那次带 "relogin": true 标记
- 成功/失败(重试用尽)两种情况都完整携带全部尝试记录
This commit is contained in:
@@ -848,7 +848,8 @@ def _signin_one_with_retry(username, password, row, sess, token):
|
|||||||
token 疑似失效(上游错误/登录错)时重新登录一次后立即重试(对齐 bot refresh 语义)。
|
token 疑似失效(上游错误/登录错)时重新登录一次后立即重试(对齐 bot refresh 语义)。
|
||||||
|
|
||||||
与 bot complete_signin 一致:除限流(外层中断)外,任何未确认成功都消耗重试次数;
|
与 bot complete_signin 一致:除限流(外层中断)外,任何未确认成功都消耗重试次数;
|
||||||
重试用尽记最终失败。返回 (entry, sess, token)。"""
|
重试用尽记最终失败。entry["attempts"] 为逐次完整记录列表(每次的结果与原因,
|
||||||
|
relogin 后立即重试的那次带 "relogin": true)。返回 (entry, sess, token)。"""
|
||||||
link = row["link"]
|
link = row["link"]
|
||||||
base = {
|
base = {
|
||||||
"activityKey": row.get("signin_activity_key"),
|
"activityKey": row.get("signin_activity_key"),
|
||||||
@@ -859,16 +860,25 @@ def _signin_one_with_retry(username, password, row, sess, token):
|
|||||||
}
|
}
|
||||||
attempts = 0
|
attempts = 0
|
||||||
refreshed = False
|
refreshed = False
|
||||||
|
relogin_before_next = False # 上一次迭代发生了重登录,下一次尝试标记 relogin
|
||||||
last_err = "unknown error"
|
last_err = "unknown error"
|
||||||
last_data = None
|
last_data = None
|
||||||
|
attempt_log = [] # 逐次记录:{"n", "success", "message"[, "relogin"]}
|
||||||
while attempts < MAX_SIGNIN_ATTEMPTS:
|
while attempts < MAX_SIGNIN_ATTEMPTS:
|
||||||
attempts += 1
|
attempts += 1
|
||||||
|
record = {"n": attempts}
|
||||||
|
if relogin_before_next:
|
||||||
|
record["relogin"] = True
|
||||||
|
relogin_before_next = False
|
||||||
try:
|
try:
|
||||||
data = fetch_sign_in_info(username, password, link, do_commit=True,
|
data = fetch_sign_in_info(username, password, link, do_commit=True,
|
||||||
sess=sess, token=token)
|
sess=sess, token=token)
|
||||||
last_data = data
|
last_data = data
|
||||||
commit = data.get("commit")
|
commit = data.get("commit")
|
||||||
if isinstance(commit, dict) and commit.get("success") is True:
|
if isinstance(commit, dict) and commit.get("success") is True:
|
||||||
|
record["success"] = True
|
||||||
|
record["message"] = "签到成功"
|
||||||
|
attempt_log.append(record)
|
||||||
entry = dict(base)
|
entry = dict(base)
|
||||||
entry.update({
|
entry.update({
|
||||||
"type": data.get("type"),
|
"type": data.get("type"),
|
||||||
@@ -878,12 +888,14 @@ def _signin_one_with_retry(username, password, row, sess, token):
|
|||||||
"status": data.get("status"),
|
"status": data.get("status"),
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": "签到成功",
|
"message": "签到成功",
|
||||||
"attempts": attempts,
|
"attempts": attempt_log,
|
||||||
})
|
})
|
||||||
return entry, sess, token
|
return entry, sess, token
|
||||||
message = ((commit or {}).get("message")
|
message = ((commit or {}).get("message")
|
||||||
or "no commit result returned")
|
or "no commit result returned")
|
||||||
last_err = str(message)
|
last_err = str(message)
|
||||||
|
record["success"] = False
|
||||||
|
record["message"] = last_err
|
||||||
except RateLimitedError:
|
except RateLimitedError:
|
||||||
raise
|
raise
|
||||||
except (UpstreamError, AuthError) as e:
|
except (UpstreamError, AuthError) as e:
|
||||||
@@ -892,14 +904,25 @@ def _signin_one_with_retry(username, password, row, sess, token):
|
|||||||
refreshed = True
|
refreshed = True
|
||||||
try:
|
try:
|
||||||
sess, token = login(username, password)
|
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
|
continue
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # 重登录也失败:落入常规退避重试
|
pass # 重登录也失败:落入常规退避重试
|
||||||
last_err = str(e) or type(e).__name__
|
last_err = str(e) or type(e).__name__
|
||||||
|
record["success"] = False
|
||||||
|
record["message"] = last_err
|
||||||
except NoSignInCodeError as e:
|
except NoSignInCodeError as e:
|
||||||
last_err = str(e)
|
last_err = str(e)
|
||||||
|
record["success"] = False
|
||||||
|
record["message"] = last_err
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
last_err = safe_error(e)
|
last_err = safe_error(e)
|
||||||
|
record["success"] = False
|
||||||
|
record["message"] = last_err
|
||||||
|
attempt_log.append(record)
|
||||||
if attempts < MAX_SIGNIN_ATTEMPTS:
|
if attempts < MAX_SIGNIN_ATTEMPTS:
|
||||||
time.sleep(SIGNIN_BACKOFF[min(attempts - 1, len(SIGNIN_BACKOFF) - 1)])
|
time.sleep(SIGNIN_BACKOFF[min(attempts - 1, len(SIGNIN_BACKOFF) - 1)])
|
||||||
entry = dict(base)
|
entry = dict(base)
|
||||||
@@ -913,7 +936,7 @@ def _signin_one_with_retry(username, password, row, sess, token):
|
|||||||
})
|
})
|
||||||
entry.update({"success": False,
|
entry.update({"success": False,
|
||||||
"message": "签到失败(重试 %d 次): %s" % (attempts, last_err),
|
"message": "签到失败(重试 %d 次): %s" % (attempts, last_err),
|
||||||
"attempts": attempts})
|
"attempts": attempt_log})
|
||||||
return entry, sess, token
|
return entry, sess, token
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user