修复(斗鱼登录): 邮箱验证码按攒批投递放大等待窗口,取码超时不再重发

生产实测斗鱼验证码邮件是攒批投递的:早高峰延迟 6~20 秒,高峰劣化到 8~13
分钟,同批请求的邮件会在同一分钟内成批到达。抽 40 个「超时」账号核对邮箱,
30 个其实收到了邮件(75%),只是迟到;另有 25% 在批次内根本没投递。

原实现等 60 秒就判超时,并在超时后换通道重试 —— 重试 = 重新发信,把邮件队列
压得更长:每账号发信量从 1.5 封涨到 3.3 封,延迟从 10 秒级恶化到 8~13 分钟,
取码成功率从 100% 掉到 20%。两个通道写的是同一个队列,发两次不会多拿码。

- 等待窗口 60 → 900 秒,新增补等 600 秒(不重发,只等迟到邮件)
- 取码超时不换通道、不整轮重试;只有发信/提交接口报错才切 iframe/wgapi
- 自动重登与接入作业不再对取码失败账号切 iframe 重跑
- 单账号总时长上限 240/300 → 1800 秒,等待接入 deadline 约束
- 文档记录实测机制与判定依据

验证:1727 passed / 6 skipped,前端 tsc -b 通过,pyright 生产代码 0 错误
This commit is contained in:
yml
2026-11-25 19:52:23 +08:00
parent 5dec234e3e
commit 9473645548
12 changed files with 245 additions and 139 deletions
@@ -54,7 +54,11 @@ from ...account_work_queue import (
fail_account_work_type,
reschedule_account_work_type,
)
from ...login_automation import collect_batch_results, run_login_batch
from ...login_automation import (
EMAIL_FALLBACK_KINDS,
collect_batch_results,
run_login_batch,
)
from ...login_failure import classify_failure
from ...login_service import LoginBatchRunner, get_relogin_limits
@@ -70,9 +74,9 @@ RETRYABLE_KINDS = frozenset({"email_code", "interrupted", "network"})
# 退避阶梯(分钟):1h → 3h → 12h → 24h,超出取最后一级。
BACKOFF_MINUTES = (60, 180, 720, 1440)
# 自动重登时给 runner 的总时长上限。默认的 600 秒会长时间占住调度线程,
# 自动化场景压到 240 秒:一轮跑不完的账号留着下一轮(它们本来就有退避)。
AUTO_MAX_TOTAL_TIME = 240
# 自动重登时给 runner 的总时长上限。必须能覆盖斗鱼验证码邮件的最坏投递延迟
# (实测 8~13 分钟),否则等待会被掐断成失败;一轮跑不完的账号反正有退避。
AUTO_MAX_TOTAL_TIME = 1800
# 邮箱配额打满后退避到次日零点,再叠加随机抖动,避免整点齐发。
QUOTA_JITTER_MINUTES = 30
@@ -783,13 +787,15 @@ def run_ck_relogin(db: Session, job: AutomationJob) -> dict[str, Any]:
max_attempts=max_attempts,
expected_account_ids=account_ids,
)
# 邮箱取码失败先切 iframe 再试一次;只对 email_code 失败,不碰极验/凭证/配额。
# 取码失败不再切 iframe 重跑:换通道 = 重新发信,斗鱼验证码是攒批投递的,
# 重发会把邮件队列压更长、flush 更晚(实测每账号发信量 1.5 -> 3.3 封后,
# 邮件延迟从 10 秒级恶化到 8~13 分钟)。取码失败交给退避重试。
fallback_success = 0
fallback_batch_id = ""
email_failed_ids = [
account_id
for account_id, (status, kind) in collect_batch_results(batch_id).items()
if status in {"failed", "error"} and kind == "email_code"
if status in {"failed", "error"} and kind in EMAIL_FALLBACK_KINDS
]
if email_failed_ids:
fallback_batch_id = run_login_batch(