refactor(fudai): 抽 _handle_in_fudai_detail 中"连续参与失败次数过多"块到 fudai_detail_helpers
将 49 行的"连续参与失败兜底"块抽到 fudai_modules/fudai_detail_helpers.py: handle_consecutive_failures_exceeded。逻辑: - 写日志 + 关闭详情页 - 按 needswitch 切换直播间或保持单间模式 - 重置 _consecutive_attend_failures 计数器 douyin_fudai.py: 3627 → 3588 行 (-39) 新增 fudai_detail_helpers.py: 63 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
34bdf44d73
commit
d34e39ec9c
2 files changed
+68
-44
No files matched your search
@@ -2278,50 +2278,11 @@ class fudai_analyse:
|
||||
consecutive_failures = getattr(self, "_consecutive_attend_failures", 0)
|
||||
max_consecutive_failures = 5 # 最多允许5次连续失败
|
||||
if consecutive_failures >= max_consecutive_failures:
|
||||
try:
|
||||
self._log_kv(
|
||||
"参与",
|
||||
"_handle_in_fudai_detail:连续参与失败次数过多,跳过此福袋",
|
||||
consecutive_failures=consecutive_failures,
|
||||
max_allowed=max_consecutive_failures,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 关闭详情页,避免卡死
|
||||
try:
|
||||
douyin_fudai_detail.close_fudai_detail(self)
|
||||
except Exception:
|
||||
pass
|
||||
# 连续失败过多时,按需切换直播间
|
||||
try:
|
||||
needswitch = bool(getattr(self, "needswitch", True))
|
||||
except Exception:
|
||||
needswitch = True
|
||||
if needswitch:
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:连续参与失败过多,切换直播间",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self.swipe_up_to_next_live()
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:连续参与失败过多,单间模式不切换",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 重置计数器,避免影响后续直播间
|
||||
try:
|
||||
self._consecutive_attend_failures = 0
|
||||
except Exception:
|
||||
pass
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
handle_consecutive_failures_exceeded,
|
||||
)
|
||||
|
||||
handle_consecutive_failures_exceeded(self, max_consecutive_failures)
|
||||
return
|
||||
|
||||
# 步骤1:检查是否是第二次打开福袋详情
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"""_handle_in_fudai_detail 辅助函数
|
||||
|
||||
从 douyin_fudai.py:_handle_in_fudai_detail 中提取的相对独立的早返回块。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def handle_consecutive_failures_exceeded(analyser, max_consecutive_failures: int) -> None:
|
||||
"""连续参与失败次数过多:关闭详情页、按需切换直播间、重置计数器。
|
||||
|
||||
调用方应在调用后立即 return(早返回)。
|
||||
"""
|
||||
from douyin.fudai import douyin_fudai_detail
|
||||
|
||||
consecutive_failures = getattr(analyser, "_consecutive_attend_failures", 0)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"_handle_in_fudai_detail:连续参与失败次数过多,跳过此福袋",
|
||||
consecutive_failures=consecutive_failures,
|
||||
max_allowed=max_consecutive_failures,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 关闭详情页,避免卡死
|
||||
try:
|
||||
douyin_fudai_detail.close_fudai_detail(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 连续失败过多时,按需切换直播间
|
||||
try:
|
||||
needswitch = bool(getattr(analyser, "needswitch", True))
|
||||
except Exception:
|
||||
needswitch = True
|
||||
|
||||
if needswitch:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:连续参与失败过多,切换直播间",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
analyser.swipe_up_to_next_live()
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:连续参与失败过多,单间模式不切换",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 重置计数器,避免影响后续直播间
|
||||
try:
|
||||
analyser._consecutive_attend_failures = 0
|
||||
except Exception:
|
||||
pass
|
||||
Reference in new issue
Block a user