把 douyin/reservation/douyin_reservation_logic.py 按职责拆成 douyin/reservation/reservation_logic/ 子包: - _common (57) 共享错误处理工具占位 + ReservationItem 类型 - helpers (130) 内部工具:标题归一化 / 相似度 / 排序 / 时间戳 - add (447) add_reservation_core_logic 主入口(添加新预约) - cleanup_validate (136) validate_back_to_reservation / cleanup_expired_reservations - queue_full (305) handle_queue_full_wait_at_earliest 队列满时等待策略 - attend_window (1437) process_reservation_attend_window 进入预约窗口(最大头) - record (328) record_high_value_reservation 高价值预约登记入口 原文件改为 53 行 re-export shim,17 个公共符号全部保留。 - process_reservation_attend_window 7 处外部引用 - handle_queue_full_wait_at_earliest 5 处外部引用 - _now_ts 5 处 / cleanup_expired_reservations 4 处 / _sort_reservations_inplace 4 处 - 其他 5 处以下 全部不需修改。 回归: - 8 个新文件 + shim compileall 通过 - pytest 353 passed / 1 skipped - 旧 import 路径与新子包路径返回同一函数对象 - _now_ts / _normalize_room_title / _calculate_string_similarity 等纯函数 调用结果与拆分前一致 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
"""reservation_logic - 高价值福袋预约核心逻辑子包。
|
|
|
|
原 douyin/reservation/douyin_reservation_logic.py 拆成 6 个子模块:
|
|
|
|
- _common 共享:错误处理工具占位 + ReservationItem 类型
|
|
- helpers 内部工具:标题归一化 / 相似度 / 排序 / 时间戳
|
|
- add add_reservation_core_logic 添加新预约
|
|
- cleanup_validate validate_back_to_reservation / cleanup_expired_reservations
|
|
- queue_full handle_queue_full_wait_at_earliest 队列满时等待策略
|
|
- attend_window process_reservation_attend_window 进入预约窗口的处理(最大头)
|
|
- record record_high_value_reservation 高价值预约登记入口
|
|
|
|
外部 import 路径不变:
|
|
``from douyin.reservation.douyin_reservation_logic import process_reservation_attend_window``
|
|
仍可用(原文件改成 re-export shim)。
|
|
"""
|
|
|
|
from ._common import (
|
|
ReservationItem,
|
|
_RESERVATION_ERROR_UTILS_AVAILABLE,
|
|
format_reservation_context,
|
|
log_reservation_error,
|
|
safe_write_state,
|
|
validate_reservation_item,
|
|
)
|
|
from .helpers import (
|
|
_calculate_string_similarity,
|
|
_extract_content_core,
|
|
_normalize_room_title_for_matching,
|
|
_now_ts,
|
|
_sort_reservations_inplace,
|
|
)
|
|
from .add import add_reservation_core_logic
|
|
from .cleanup_validate import (
|
|
cleanup_expired_reservations,
|
|
validate_back_to_reservation,
|
|
)
|
|
from .queue_full import handle_queue_full_wait_at_earliest
|
|
from .attend_window import process_reservation_attend_window
|
|
from .record import record_high_value_reservation
|
|
|
|
__all__ = [
|
|
"ReservationItem",
|
|
"_RESERVATION_ERROR_UTILS_AVAILABLE",
|
|
"log_reservation_error",
|
|
"safe_write_state",
|
|
"format_reservation_context",
|
|
"validate_reservation_item",
|
|
"_now_ts",
|
|
"_normalize_room_title_for_matching",
|
|
"_calculate_string_similarity",
|
|
"_extract_content_core",
|
|
"_sort_reservations_inplace",
|
|
"add_reservation_core_logic",
|
|
"validate_back_to_reservation",
|
|
"cleanup_expired_reservations",
|
|
"handle_queue_full_wait_at_earliest",
|
|
"process_reservation_attend_window",
|
|
"record_high_value_reservation",
|
|
]
|