|
|
@@ -6,14 +6,14 @@ import random
|
|
|
from datetime import datetime
|
|
|
from typing import List, Dict, Callable, Optional
|
|
|
|
|
|
-from vs_types import (
|
|
|
- GroupConfig, VSPlgConfig, Task, VSBookResult, VSQueryResult,
|
|
|
+from core_types import (
|
|
|
+ GroupConfig, PluginConfig, Task, BookResult, QueryResult,
|
|
|
AppointmentType, QueryWaitMode, AvailabilityStatus, GroupStatus, PluginStatus, utc_now_str,
|
|
|
BizException, RateLimiteddError, SessionExpiredOrInvalidError, PermissionDeniedError,
|
|
|
NetworkTimeoutError
|
|
|
)
|
|
|
-from vs_plg_factory import VSPlgFactory
|
|
|
-from toolkit.vs_cloud_api import VSCloudApi
|
|
|
+from plugin_factory import PluginFactory
|
|
|
+from toolkit.cloud_api import CloudApi
|
|
|
from toolkit.proxy_manager import ProxyManager
|
|
|
from toolkit.thread_pool import ThreadPool
|
|
|
from toolkit.notifier import notify_book_result
|
|
|
@@ -28,7 +28,7 @@ class BaseBookerGCO:
|
|
|
|
|
|
def __init__(self, cfg: GroupConfig, redis_conf: Dict, logger: Callable[[str], None] = None):
|
|
|
self.m_cfg = cfg
|
|
|
- self.m_factory = VSPlgFactory()
|
|
|
+ self.m_factory = PluginFactory()
|
|
|
self.m_logger = logger
|
|
|
self.m_tasks: List[Task] = []
|
|
|
self.m_lock = threading.RLock()
|
|
|
@@ -171,7 +171,7 @@ class BaseBookerGCO:
|
|
|
action: str,
|
|
|
err: Exception,
|
|
|
task: Optional[Task] = None,
|
|
|
- plg_cfg: Optional[VSPlgConfig] = None,
|
|
|
+ plg_cfg: Optional[PluginConfig] = None,
|
|
|
task_id: Optional[int] = None
|
|
|
) -> None:
|
|
|
"""
|
|
|
@@ -197,7 +197,7 @@ class BaseBookerGCO:
|
|
|
self._log(f"🔒 [Account Rate Limited] 429 throttled during {action} (Account credential/frequency restricted).")
|
|
|
if acc and getattr(acc, "username", "") not in ("", "Guest") and getattr(acc, "id", 0):
|
|
|
try:
|
|
|
- VSCloudApi.Instance().lock_account(acc.id, int(backoff))
|
|
|
+ CloudApi.Instance().lock_account(acc.id, int(backoff))
|
|
|
self._log(f"🔒 Account [{acc.username}] locked for {int(backoff)}s via Cloud API.")
|
|
|
except Exception as lock_err:
|
|
|
self._log(f"Failed to lock account via cloud API: {lock_err}")
|
|
|
@@ -306,7 +306,7 @@ class BaseBookerGCO:
|
|
|
"""子类维护循环中对于健康/异常 Task 的额外处理"""
|
|
|
pass
|
|
|
|
|
|
- def _is_date_of_interest(self, task: Task, query_result: VSQueryResult) -> bool:
|
|
|
+ def _is_date_of_interest(self, task: Task, query_result: QueryResult) -> bool:
|
|
|
"""判断 query_result 中的可用日期是否在 task 意向范围内(默认 True,Order 模式重写)"""
|
|
|
return True
|
|
|
|
|
|
@@ -323,7 +323,7 @@ class BaseBookerGCO:
|
|
|
continue
|
|
|
try:
|
|
|
data = json.loads(raw_data)
|
|
|
- query_result = VSQueryResult.model_validate(data['query_result'])
|
|
|
+ query_result = QueryResult.model_validate(data['query_result'])
|
|
|
query_result.apt_type = AppointmentType.model_validate(data['apt_type'])
|
|
|
except Exception as parse_err:
|
|
|
self._log(f"Data parsing error for {redis_key}: {parse_err}. Deleting corrupted signal.")
|
|
|
@@ -357,7 +357,7 @@ class BaseBookerGCO:
|
|
|
except Exception as e:
|
|
|
self._log(f"Booking trigger loop exception: {e}")
|
|
|
|
|
|
- def _execute_book_job(self, task: Task, query_result: VSQueryResult):
|
|
|
+ def _execute_book_job(self, task: Task, query_result: QueryResult):
|
|
|
raise NotImplementedError
|
|
|
|
|
|
def _creator_loop(self):
|
|
|
@@ -377,7 +377,7 @@ class BaseBookerGCO:
|
|
|
|
|
|
def _update_cloud_success():
|
|
|
try:
|
|
|
- VSCloudApi.Instance().update_vas_task(str(task_id), {"status": "grabbed", "grabbed_history": grab_info})
|
|
|
+ CloudApi.Instance().update_vas_task(str(task_id), {"status": "grabbed", "grabbed_history": grab_info})
|
|
|
except Exception as e:
|
|
|
self._log(f"Failed to update success state to cloud: {e}")
|
|
|
|
|
|
@@ -416,13 +416,13 @@ class BuiltinBookerGCO(BaseBookerGCO):
|
|
|
plg_cfg = None
|
|
|
|
|
|
try:
|
|
|
- plg_cfg = VSPlgConfig()
|
|
|
+ plg_cfg = PluginConfig()
|
|
|
plg_cfg.debug = self.m_cfg.debug
|
|
|
plg_cfg.free_config = self.m_cfg.free_config
|
|
|
plg_cfg.session_max_life = self.m_cfg.session_max_life
|
|
|
|
|
|
if self.m_cfg.need_account:
|
|
|
- acc = VSCloudApi.Instance().get_next_account(self.m_cfg.booker.account_pool_id, self.m_cfg.booker.account_cd)
|
|
|
+ acc = CloudApi.Instance().get_next_account(self.m_cfg.booker.account_pool_id, self.m_cfg.booker.account_cd)
|
|
|
plg_cfg.account = type(plg_cfg.account)(**acc)
|
|
|
|
|
|
if self.m_cfg.need_proxy:
|
|
|
@@ -455,14 +455,14 @@ class BuiltinBookerGCO(BaseBookerGCO):
|
|
|
if not success and instance:
|
|
|
self._cleanup_instance(instance, "spawn failed")
|
|
|
|
|
|
- def _execute_book_job(self, task: Task, query_result: VSQueryResult):
|
|
|
+ def _execute_book_job(self, task: Task, query_result: QueryResult):
|
|
|
queue_name = f"auto.{query_result.apt_type.routing_key}"
|
|
|
|
|
|
task_id = None
|
|
|
task_data = None
|
|
|
|
|
|
try:
|
|
|
- task_data = VSCloudApi.Instance().get_vas_task_pop(queue_name)
|
|
|
+ task_data = CloudApi.Instance().get_vas_task_pop(queue_name)
|
|
|
if not task_data:
|
|
|
return
|
|
|
task_id = task_data['id']
|
|
|
@@ -541,7 +541,7 @@ class OrderBookerGCO(BaseBookerGCO):
|
|
|
now = time.time()
|
|
|
for tid, last_refresh in tasks_to_check.items():
|
|
|
if now - last_refresh >= refresh_interval:
|
|
|
- fresh_data = VSCloudApi.Instance().get_vas_task(tid)
|
|
|
+ fresh_data = CloudApi.Instance().get_vas_task(tid)
|
|
|
if fresh_data:
|
|
|
fresh_data['_last_refresh'] = time.time()
|
|
|
|
|
|
@@ -552,7 +552,7 @@ class OrderBookerGCO(BaseBookerGCO):
|
|
|
except Exception as e:
|
|
|
self._log(f'Cache refresh loop exception: {e}')
|
|
|
|
|
|
- def _is_date_of_interest(self, task: Task, query_result: VSQueryResult) -> bool:
|
|
|
+ def _is_date_of_interest(self, task: Task, query_result: QueryResult) -> bool:
|
|
|
if query_result.availability_status != AvailabilityStatus.Available:
|
|
|
return True
|
|
|
task_id = task.task_ref
|
|
|
@@ -566,7 +566,7 @@ class OrderBookerGCO(BaseBookerGCO):
|
|
|
dt = available_date.strftime("%Y-%m-%d")
|
|
|
return dt <= expected_end_date
|
|
|
|
|
|
- def _execute_book_job(self, task: Task, query_result: VSQueryResult):
|
|
|
+ def _execute_book_job(self, task: Task, query_result: QueryResult):
|
|
|
task_id = task.task_ref
|
|
|
task_data = None
|
|
|
|
|
|
@@ -617,7 +617,7 @@ class OrderBookerGCO(BaseBookerGCO):
|
|
|
task_id = None
|
|
|
try:
|
|
|
queue_name = f"auto.{target_routing_key}"
|
|
|
- task_data = VSCloudApi.Instance().get_vas_task_pop(queue_name)
|
|
|
+ task_data = CloudApi.Instance().get_vas_task_pop(queue_name)
|
|
|
if not task_data:
|
|
|
return
|
|
|
|
|
|
@@ -629,7 +629,7 @@ class OrderBookerGCO(BaseBookerGCO):
|
|
|
self.redis_client.zadd(self.m_tracker_key, {str(task_id): time.time() + 8*60.0})
|
|
|
user_inputs = task_data.get('user_inputs', {})
|
|
|
|
|
|
- plg_cfg = VSPlgConfig()
|
|
|
+ plg_cfg = PluginConfig()
|
|
|
plg_cfg.debug = self.m_cfg.debug
|
|
|
plg_cfg.free_config = self.m_cfg.free_config
|
|
|
plg_cfg.session_max_life = self.m_cfg.session_max_life
|