Fix patrol delete condition handling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
import uuid
|
||||
@@ -20,7 +21,7 @@ except ImportError:
|
||||
STATUS_OK = "0"
|
||||
STATUS_LOGIN_FAILED = "-10003"
|
||||
|
||||
DEFAULT_SOCKET_PORT = 19890
|
||||
DEFAULT_SOCKET_PORT = 20000
|
||||
CLIENT_API_TIMEOUT = 120
|
||||
PORT_CHECK_TIMEOUT = 2
|
||||
UPDATE_CORE_RETRY_DELAY = 2
|
||||
@@ -30,6 +31,7 @@ CLIENT_READY_TIMEOUT = 10
|
||||
CLIENT_READY_INTERVAL = 0.5
|
||||
CLIENT_POST_START_DELAY = 5
|
||||
PROCESS_KILL_DELAY = 3
|
||||
ZINIAO_WEBDRIVER_LOG_TAIL_LINES = 80
|
||||
|
||||
DOC_LOAD_TIMEOUT = 30
|
||||
COUNTRY_INITIAL_LOAD_TIMEOUT = 120
|
||||
@@ -152,6 +154,49 @@ class ZiniaoDriver:
|
||||
time.sleep(CLIENT_READY_INTERVAL)
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _redact_ziniao_log_line(line: str) -> str:
|
||||
return re.sub(r'("password"\s*:\s*)"[^"]*"', r'\1"***"', line)
|
||||
|
||||
@staticmethod
|
||||
def _ziniao_webdriver_log_path() -> Optional[str]:
|
||||
appdata = os.getenv("APPDATA")
|
||||
if not appdata:
|
||||
return None
|
||||
filename = f"webdriver.{time.strftime('%Y%m%d')}.log"
|
||||
return os.path.join(
|
||||
appdata,
|
||||
"ziniaobrowser",
|
||||
"instances",
|
||||
"userdata1",
|
||||
"logs",
|
||||
"client",
|
||||
filename,
|
||||
)
|
||||
|
||||
def _log_ziniao_webdriver_tail(self) -> None:
|
||||
log_path = self._ziniao_webdriver_log_path()
|
||||
if not log_path:
|
||||
logger.warning("无法读取紫鸟 webdriver 日志: APPDATA 环境变量为空")
|
||||
return
|
||||
if not os.path.exists(log_path):
|
||||
logger.warning("紫鸟 webdriver 日志不存在:{}", log_path)
|
||||
return
|
||||
|
||||
try:
|
||||
with open(log_path, "r", encoding="utf-8", errors="replace") as log_file:
|
||||
lines = log_file.readlines()
|
||||
except OSError as exc:
|
||||
logger.warning("读取紫鸟 webdriver 日志失败:{} | {}", log_path, exc)
|
||||
return
|
||||
|
||||
tail_lines = lines[-ZINIAO_WEBDRIVER_LOG_TAIL_LINES:]
|
||||
tail_text = "".join(self._redact_ziniao_log_line(line) for line in tail_lines).strip()
|
||||
if tail_text:
|
||||
logger.error("紫鸟 webdriver 日志尾部({}):\n{}", log_path, tail_text)
|
||||
else:
|
||||
logger.warning("紫鸟 webdriver 日志为空:{}", log_path)
|
||||
|
||||
def get_zinaio_exe(self, protocol_name: str = "superbrowser"):
|
||||
"""从 Windows 注册表读取紫鸟客户端可执行文件路径.
|
||||
|
||||
@@ -402,7 +447,7 @@ class ZiniaoDriver:
|
||||
|
||||
for retry_count in range(CLIENT_START_RETRIES):
|
||||
logger.info("第 {}/{} 次尝试启动紫鸟客户端", retry_count + 1, CLIENT_START_RETRIES)
|
||||
subprocess.Popen(cmd)
|
||||
process = subprocess.Popen(cmd)
|
||||
|
||||
if self._wait_until_client_ready(CLIENT_READY_TIMEOUT):
|
||||
logger.info("紫鸟客户端启动成功,第 {} 次尝试", retry_count + 1)
|
||||
@@ -411,6 +456,9 @@ class ZiniaoDriver:
|
||||
return
|
||||
|
||||
logger.warning("第 {} 次尝试启动失败,10秒内未检测到客户端启动", retry_count + 1)
|
||||
if process.poll() is not None:
|
||||
logger.warning("紫鸟客户端进程已退出,returncode={}", process.returncode)
|
||||
self._log_ziniao_webdriver_tail()
|
||||
|
||||
logger.error("紫鸟客户端启动失败,已重试 {} 次", CLIENT_START_RETRIES)
|
||||
raise RuntimeError(f"客户端启动失败:重试 {CLIENT_START_RETRIES} 次后仍未成功启动")
|
||||
|
||||
Reference in New Issue
Block a user