Jelajahi Sumber

feat: update

Hujiarui 2 bulan lalu
induk
melakukan
5eecf2482f
6 mengubah file dengan 55 tambahan dan 12 penghapusan
  1. 16 2
      booker_builtin.py
  2. 15 2
      booker_order.py
  3. 4 4
      plugins/tls_plugin.py
  4. 3 4
      plugins/vfs_plugin.py
  5. 15 0
      sentinel.py
  6. 2 0
      vs_types.py

+ 16 - 2
booker_builtin.py

@@ -3,6 +3,7 @@ import time
 import json
 import threading
 import random
+from datetime import datetime
 from typing import List, Dict, Callable
 
 from vs_types import GroupConfig, VSPlgConfig, Task, VSQueryResult, AppointmentType
@@ -92,6 +93,17 @@ class BuiltinBookerGCO:
 
     def _get_redis_key(self, routing_key: str) -> str:
         return f"vs:signal:{routing_key}"
+    
+    def _is_within_active_hours(self) -> bool:
+        """
+        判断当前是否在允许创建实例的时间段内
+        """
+        start_str = self.m_cfg.active_time_start
+        end_str = self.m_cfg.active_time_end
+        current_bj_time = datetime.now().time()
+        start_time = datetime.strptime(start_str, "%H:%M").time()
+        end_time = datetime.strptime(end_str, "%H:%M").time()
+        return start_time <= current_bj_time <= end_time
 
     def _maintain_loop(self):
         self._log("Maintain loop started.")
@@ -246,9 +258,11 @@ class BuiltinBookerGCO:
                 
     def _creator_loop(self):
         self._log("Creator loop started.")
-        while not self.m_stop_event.is_set():
+        while not self.m_stop_event.wait(1.0):
             try:
-                time.sleep(1.0)
+                if not self._is_within_active_hours():
+                    continue
+                
                 with self.m_lock:
                     current = len(self.m_tasks)
                     target = self.m_cfg.booker.target_instances

+ 15 - 2
booker_order.py

@@ -3,6 +3,7 @@ import time
 import json
 import threading
 import random
+from datetime import datetime
 from typing import List, Dict, Callable
 
 from vs_types import GroupConfig, VSPlgConfig, Task, VSQueryResult, AppointmentType, AvailabilityStatus
@@ -101,6 +102,17 @@ class OrderBookerGCO:
 
     def _get_redis_key(self, routing_key: str) -> str:
         return f"vs:signal:{routing_key}"
+    
+    def _is_within_active_hours(self) -> bool:
+        """
+        判断当前是否在允许创建实例的时间段内
+        """
+        start_str = self.m_cfg.active_time_start
+        end_str = self.m_cfg.active_time_end
+        current_bj_time = datetime.now().time()
+        start_time = datetime.strptime(start_str, "%H:%M").time()
+        end_time = datetime.strptime(end_str, "%H:%M").time()
+        return start_time <= current_bj_time <= end_time
             
     def _maintain_loop(self):
         self._log("Maintain loop started.")
@@ -305,9 +317,10 @@ class OrderBookerGCO:
                     
     def _creator_loop(self):
         self._log("Creator loop started.")
-        while not self.m_stop_event.is_set():
+        while not self.m_stop_event.wait(1.0):
             try:
-                time.sleep(1)
+                if not self._is_within_active_hours():
+                    continue
                 for apt in self.m_cfg.appointment_types:
                     r_key = apt.routing_key
                     with self.m_lock:

+ 4 - 4
plugins/tls_plugin.py

@@ -74,9 +74,9 @@ class TlsPlugin(IVSPlg):
     
     def _log(self, message):
         if self.logger:
-            self.logger(f'[TlsPlugin] [{self.group_id}] {message}')
+            self.logger(f'[TlsPlugin] [{self.group_id}] [{self.instance_id}] {message}')
         else:
-            print(f'[TlsPlugin] [{self.group_id}] {message}')
+            print(f'[TlsPlugin] [{self.group_id}] [{self.instance_id}] {message}')
 
     def set_config(self, config: VSPlgConfig):
         self.config = config
@@ -174,7 +174,8 @@ class TlsPlugin(IVSPlg):
         
         debug_port = get_free_port()
         self._log(f"Assigned Debug Port: {debug_port}")
-        
+        self._log(f"Account id={self.config.account.id}, proxy id={self.config.proxy.id}")
+    
         co.set_local_port(debug_port)       
         co.set_user_data_path(self.user_data_path)
         
@@ -186,7 +187,6 @@ class TlsPlugin(IVSPlg):
         
         if self.config.proxy and self.config.proxy.ip:
             p = self.config.proxy
-            self._log(f'Current proxy id={p.id}')
             if p.username and p.password:
                 self._log(f"Starting Proxy Tunnel for {p.ip}...")
                 exit_node = {

+ 3 - 4
plugins/vfs_plugin.py

@@ -158,9 +158,9 @@ class VfsPlugin(IVSPlg):
     
     def _log(self, message):
         if self.logger:
-            self.logger(f'[VfsPlugin] [{self.group_id}] {message}')
+            self.logger(f'[TlsPlugin] [{self.group_id}] [{self.instance_id}] {message}')
         else:
-            print(f'[VfsPlugin] [{self.group_id}] {message}')
+            print(f'[TlsPlugin] [{self.group_id}] [{self.instance_id}] {message}')
             
     def keep_alive(self):
         try:
@@ -211,7 +211,7 @@ class VfsPlugin(IVSPlg):
         
         debug_port = get_free_port()
         self._log(f"Assigned Debug Port: {debug_port}")
-        
+        self._log(f"Account id={self.config.account.id}, proxy id={self.config.proxy.id}")
         co.set_local_port(debug_port)
         co.set_user_data_path(self.user_data_path)
         
@@ -223,7 +223,6 @@ class VfsPlugin(IVSPlg):
         
         if self.config.proxy and self.config.proxy.ip:
             p = self.config.proxy
-            self._log(f'Current proxy id={p.id}')
             if p.username and p.password:
                 self._log(f"Starting Proxy Tunnel for {p.ip}...")
                 exit_node = {

+ 15 - 0
sentinel.py

@@ -3,6 +3,7 @@ import time
 import json
 import random
 import threading
+from datetime import datetime
 from typing import List, Dict, Callable
 
 from vs_types import GroupConfig, VSPlgConfig, Task, QueryWaitMode
@@ -91,6 +92,17 @@ class SentinelGCO:
 
     def _get_redis_key(self, routing_key: str) -> str:
         return f"vs:signal:{routing_key}"
+    
+    def _is_within_active_hours(self) -> bool:
+        """
+        判断当前是否在允许创建实例的时间段内
+        """
+        start_str = self.m_cfg.active_time_start
+        end_str = self.m_cfg.active_time_end
+        current_bj_time = datetime.now().time()
+        start_time = datetime.strptime(start_str, "%H:%M").time()
+        end_time = datetime.strptime(end_str, "%H:%M").time()
+        return start_time <= current_bj_time <= end_time
 
     def _monitor_loop(self):
         self._log("Monitor loop started.")
@@ -189,6 +201,9 @@ class SentinelGCO:
         self._log("Creator loop started.")
         while not self.m_stop_event.wait(1.0):
             try:
+                if not self._is_within_active_hours():
+                    continue
+                
                 with self.m_lock:
                     current = len(self.m_tasks)
                     target = self.m_cfg.sentinel.target_instances

+ 2 - 0
vs_types.py

@@ -107,6 +107,8 @@ class GroupConfig(BaseModel):
     need_proxy: bool = False
     proxy_pool: List[str] = Field(default_factory=list)
     proxy_cd: int = 5*60                # 单位 秒
+    active_time_start: str = "00:00"    # 默认执行起始时间
+    active_time_end: str = "23:59"      # 默认执行结束时间
     session_max_life: int = 30*60       # 单位 秒
     login_backoff: int = 1800           # 创建会话Rate limited 后账号自动退避 秒
     sentinel: SentinelConfig = Field(default_factory=SentinelConfig)