Refactor reservation preemption handling and logging
- Removed the reservation preempt minimum value from the Runner and GUI components. - Updated logging mechanism to streamline log message handling and improve readability. - Introduced a new method for appending log lines in the Runner class. - Cleaned up related GUI elements and configuration options in web interface. - Deleted obsolete simulation scripts related to reservation preemption checks.
This commit is contained in:
1 parent
eb96d6869e
commit
93d47a16d6
20 files changed
+786
-1051
No files matched your search
+22
-44
@@ -1,15 +1,16 @@
|
||||
# 抖音福袋挂机 — 完整技术文档(重构)
|
||||
|
||||
版本: V4.0
|
||||
最后更新: 2026-01-03
|
||||
版本: V4.1
|
||||
最后更新: 2026-01-07
|
||||
目标读者: 开发者、维护者、运维与 AI 助手
|
||||
|
||||
说明:本文件为项目主要技术文档的重构版,聚焦“快速上手、配置规范、关键模块地图、运行与排障、验证清单”。文档同时给出可执行的诊断/采样命令,便于自动化采集与 CI 校验。
|
||||
|
||||
-- 变更记录
|
||||
- 2026-01-07: V4.1 — 删除所有预约抢占逻辑,包括配置项、代码实现和相关文档。
|
||||
- 2026-01-03: V4.0 — 重构文档结构,补充快速上手、配置优先级、截图/OCR/日志说明、故障排查与验证清单。
|
||||
|
||||
## 最近修复与配置变更(2026-01-03)
|
||||
## 最近修复与配置变更(2026-01-07)
|
||||
|
||||
本小节记录最近完成的若干修复与功能开关,便于开发与运维快速验证和回滚。
|
||||
|
||||
@@ -30,26 +31,21 @@
|
||||
- 日志写法修正:将 ad-hoc 的直接写 actions.log 的行为替换为通过统一 logger 输出,避免 RotatingFileHandler 在 Windows 上轮转时报 WinError 32(文件被占用)。相关调整见 `douyin/handlers/douyin_screenshot_manager.py` / `douyin/logging/*`。
|
||||
|
||||
- 验证要点(运行时观察):
|
||||
- 当 `fudai_disable_content_recognition` 为 true 时,日志中应出现至少一条:
|
||||
- `跳过福袋内容OCR识别(配置启用)` 或 `跳过备用福袋内容OCR识别(配置启用)` 或 `跳过串行福袋内容OCR识别(配置启用)`。
|
||||
- 并且不会出现新的 `OCR识别福袋内容` 的性能/计时条目(即不再有与 content OCR 相关的耗时统计)。
|
||||
- 当 `fudai_disable_task_recognition` 为 true 时,日志中应出现:
|
||||
- `跳过福袋任务列表OCR识别(配置启用)`,并且不会有任务列表 OCR 的原始输出条目。
|
||||
- 连续未找到福袋触发退出:将 `fudai_exit_after_misses` 设为小值(例如 3),运行短会话,日志应出现类似:
|
||||
- `连续未找到福袋达到阈值:按返回键退出直播间`(或相近日志),并能在 `logs/actions.log` 中看到对应的返回按键事件。
|
||||
- actions.log 轮转问题:在长时间运行后触发日志轮转,确认不会再出现 Windows 的 `PermissionError` / `WinError 32` 异常。
|
||||
- 预约系统不再执行抢占行为,日志中不会出现抢占相关的处理信息
|
||||
- 配置文件中不再包含抢占相关配置项
|
||||
- 代码中不再有抢占逻辑的分支判断
|
||||
|
||||
- 快速验证命令(仓库根目录,PowerShell):
|
||||
|
||||
```powershell
|
||||
# 语法检查
|
||||
python -m py_compile douyin/fudai/core/fudai_detail_reader.py
|
||||
python -m py_compile douyin/core/douyin_fudai.py
|
||||
|
||||
# 在 config 里临时启用开关(手动修改 config/config.json)后运行一次短会话
|
||||
# 运行短会话验证预约功能正常
|
||||
python run_cli.py --wait-minutes 0 --device-id <ADB_ID>
|
||||
|
||||
# 在日志中查找跳过消息(示例)
|
||||
Select-String -Path logs\*.log -Pattern "跳过福袋内容OCR识别|跳过福袋任务列表OCR识别|连续未找到福袋"
|
||||
# 检查配置文件中是否删除了抢占相关配置项
|
||||
Select-String -Path config/config.json -Pattern "preempt|poll_before"
|
||||
```
|
||||
|
||||
如果需要,我可以把这些验证步骤写成一键脚本 `tools/verify_fudai_disable.sh` / `tools/verify_fudai_disable.ps1` 以便 CI 调用。
|
||||
@@ -411,7 +407,7 @@ run_once_basic(recursion_depth=0)
|
||||
└─> 如需回退则在回退流程中直接处理参与逻辑(不再使用 `_reservation_back_direct_attend` 或 `_force_attend_after_reservation_back` 标志)
|
||||
↓
|
||||
[检查2] 等待开奖状态 (_waiting_for_lottery_result)
|
||||
├─> 是 → 检查预约抢占 → 检查开奖结果 → return
|
||||
├─> 是 → 检查开奖结果 → return
|
||||
└─> 否 → 继续
|
||||
↓
|
||||
[检查3] 30分钟超时检查
|
||||
@@ -721,10 +717,7 @@ def fudai_choujiang(self, device_id: str = "", y_pianyi: int = 0,
|
||||
|
||||
**0. 检查等待开奖状态** (`_waiting_for_lottery_result`)
|
||||
- 如果为 `True`,执行以下逻辑:
|
||||
1. **检查预约抢占**:
|
||||
- 如果启用高价值预约且预约队列不为空,调用 `process_reservation_attend_window()` 检查是否需要抢占
|
||||
- 如果检测到预约需要处理,清除等待开奖标志,中断等待,继续执行后续逻辑
|
||||
2. **等待开奖时间检查**:
|
||||
1. **等待开奖时间检查**:
|
||||
- 计算剩余秒数:`remain_seconds = max(0, future_ts - current_ts + 6.0)`(加上6秒延迟修正)
|
||||
- 开奖检测开始时间:`check_start_ts = future_ts + 1.0`(开奖时间+1秒缓冲)
|
||||
- 超时时间:`timeout_ts = future_ts + 10.0`(超过开奖时间10秒清除等待标志)
|
||||
@@ -787,14 +780,7 @@ def run_once_basic(self) -> None:
|
||||
|
||||
# 0. 检查等待开奖状态
|
||||
if getattr(self, "_waiting_for_lottery_result", False):
|
||||
# 检查预约抢占
|
||||
if high_value_enabled and reservations:
|
||||
preempted = process_reservation_attend_window(...)
|
||||
if preempted:
|
||||
self._waiting_for_lottery_result = False
|
||||
# 继续执行后续逻辑
|
||||
else:
|
||||
# 等待开奖时间检查
|
||||
# 等待开奖时间检查
|
||||
remain_seconds = max(0, future_ts - current_ts + 6.0)
|
||||
check_start_ts = future_ts + 1.0
|
||||
timeout_ts = future_ts + 10.0
|
||||
@@ -2785,8 +2771,7 @@ UNKNOWN = "UNKNOWN" # 未知阶段
|
||||
"high_value_room_revisit_enabled": true, // 是否启用高价值直播间重访
|
||||
"high_value_room_revisit_only_current_run": true, // 是否仅在当前运行中重访
|
||||
"reservation_back_verify_enabled": true, // 是否验证预约回退
|
||||
"reservation_back_swipe_delay": 0.1, // 预约回退滑动延迟(秒)
|
||||
"reservation_preempt_min_value": 0.0 // 预约抢占最小价值(元)
|
||||
"reservation_back_swipe_delay": 0.1 // 预约回退滑动延迟(秒)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2802,7 +2787,6 @@ UNKNOWN = "UNKNOWN" # 未知阶段
|
||||
- **`high_value_room_revisit_only_current_run`**: 是否仅在当前运行中重访(重启后不保留)
|
||||
- **`reservation_back_verify_enabled`**: 是否验证预约回退(回退后验证是否在目标直播间)
|
||||
- **`reservation_back_swipe_delay`**: 预约回退滑动后的延迟(秒)
|
||||
- **`reservation_preempt_min_value`**: 预约抢占最小价值(如果新福袋价值更高,可以抢占旧预约)
|
||||
|
||||
#### 7.2.4 福袋查找配置
|
||||
|
||||
@@ -3038,16 +3022,11 @@ if self._reservation_back_direct_attend:
|
||||
```python
|
||||
# 在 run_once_basic() 中
|
||||
if self._waiting_for_lottery_result:
|
||||
# 检查预约抢占
|
||||
if self._check_reservation_preempt():
|
||||
self._waiting_for_lottery_result = False
|
||||
return
|
||||
|
||||
# 检查开奖结果
|
||||
if time.time() >= self._lottery_result_expected_ts:
|
||||
self._handle_lottery_result()
|
||||
self._waiting_for_lottery_result = False
|
||||
return
|
||||
# 检查开奖结果
|
||||
if time.time() >= self._lottery_result_expected_ts:
|
||||
self._handle_lottery_result()
|
||||
self._waiting_for_lottery_result = False
|
||||
return
|
||||
```
|
||||
|
||||
#### 8.2.3 跳过阶段诊断标志
|
||||
@@ -3188,9 +3167,8 @@ def save_reservations_to_state(analyser):
|
||||
|
||||
1. **设置等待状态**: 参与福袋后,如果倒计时较长(> 30秒),设置等待状态
|
||||
2. **等待期间**: 继续运行主循环,但跳过福袋查找和参与
|
||||
3. **检查预约抢占**: 如果发现更高价值的预约,取消当前等待
|
||||
4. **检查开奖结果**: 到达预期开奖时间后,检查开奖结果
|
||||
5. **清除等待状态**: 处理完开奖结果后清除
|
||||
3. **检查开奖结果**: 到达预期开奖时间后,检查开奖结果
|
||||
4. **清除等待状态**: 处理完开奖结果后清除
|
||||
|
||||
**代码示例**:
|
||||
```python
|
||||
|
||||
Reference in new issue
Block a user