优化代理获取和登录逻辑
- 每个账号独立获取代理,不再共用一个代理IP - 代理预检失败只标记该账号失败,不终止整个批次 - 代理验证改为并发:verify_proxies_concurrent 多IP同时验证 - resolve_working_proxy 多IP并发验证,找到可用即返回 - parse_proxy_response 改为返回列表,支持多行/逗号分隔 - 邮箱验证码匹配收件人地址,防止多账号并发取错验证码 - 修正 mail.bdhg.xyz 旧数据端口和SSL配置 - bdhg.xyz 默认配置改为 143端口非SSL Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
9f6b405571
commit
8fdf8d4b69
@@ -64,6 +64,12 @@ def _migrate():
|
||||
"WHERE email_imap_server = '111.229.206.54'"
|
||||
))
|
||||
conn.commit()
|
||||
# 修正旧数据中使用 mail.bdhg.xyz 的账号:993端口不通,改用143非SSL
|
||||
conn.execute(text(
|
||||
"UPDATE accounts SET email_imap_port = 143, email_imap_ssl = 0 "
|
||||
"WHERE email_imap_server = 'mail.bdhg.xyz'"
|
||||
))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def _seed():
|
||||
|
||||
@@ -93,8 +93,8 @@ class LoginBatchRunner:
|
||||
|
||||
return None, ''
|
||||
|
||||
def _execute_one(self, task_id: int, acc_info: dict, proxy_dict: Optional[dict], total: int):
|
||||
"""在独立线程中执行单个账号登录,使用独立的 DB 会话。"""
|
||||
def _execute_one(self, task_id: int, acc_info: dict, total: int):
|
||||
"""在独立线程中执行单个账号登录,使用独立的 DB 会话和代理。"""
|
||||
if self._stop.is_set():
|
||||
self._push_log("warning", f"任务已停止,跳过: {acc_info['username']}")
|
||||
return
|
||||
@@ -114,6 +114,20 @@ class LoginBatchRunner:
|
||||
|
||||
self._push_log("info", f"[{current}/{total}] 开始登录: {acc_info['username']}")
|
||||
|
||||
# 每个账号独立获取代理
|
||||
proxy_dict, proxy_msg = self._resolve_proxy()
|
||||
if proxy_msg:
|
||||
self._push_log("info", f"[{current}] {proxy_msg}")
|
||||
|
||||
# 代理预检失败时,该账号标记失败但不终止整个批次
|
||||
if self.proxy_config and self.proxy_config.enabled and not proxy_dict:
|
||||
task.status = "error"
|
||||
task.message = f"代理不可用: {proxy_msg}"
|
||||
task.finished_at = datetime.now(timezone.utc)
|
||||
worker_db.commit()
|
||||
self._push_log("error", f"[{current}] {acc_info['username']} 代理不可用: {proxy_msg}")
|
||||
return
|
||||
|
||||
try:
|
||||
account = Account(
|
||||
username=acc_info["username"],
|
||||
@@ -217,29 +231,7 @@ class LoginBatchRunner:
|
||||
self._push_log("result", "")
|
||||
return
|
||||
|
||||
# 代理预检
|
||||
proxy_dict, proxy_msg = self._resolve_proxy()
|
||||
if proxy_msg:
|
||||
self._push_log("info", proxy_msg)
|
||||
|
||||
# 如果启用了代理但预检失败,终止任务
|
||||
if self.proxy_config and self.proxy_config.enabled and not proxy_dict:
|
||||
self._push_log("error", f"代理不可用,任务终止: {proxy_msg}")
|
||||
for item in task_infos:
|
||||
worker_db = SessionLocal()
|
||||
try:
|
||||
task = worker_db.query(LoginTask).filter(LoginTask.id == item["task_id"]).first()
|
||||
if task:
|
||||
task.status = "error"
|
||||
task.message = f"代理不可用: {proxy_msg}"
|
||||
task.finished_at = datetime.now(timezone.utc)
|
||||
worker_db.commit()
|
||||
finally:
|
||||
worker_db.close()
|
||||
self._push_log("result", "")
|
||||
return
|
||||
|
||||
# 并发执行登录
|
||||
# 并发执行登录,每个账号独立获取代理
|
||||
with ThreadPoolExecutor(max_workers=concurrency) as executor:
|
||||
futures = []
|
||||
for item in task_infos:
|
||||
@@ -250,7 +242,6 @@ class LoginBatchRunner:
|
||||
self._execute_one,
|
||||
item["task_id"],
|
||||
item["acc_info"],
|
||||
proxy_dict,
|
||||
total,
|
||||
)
|
||||
futures.append(future)
|
||||
|
||||
Reference in New Issue
Block a user