fix: 补齐审查清单里还没落地的交互和代理复测

This commit is contained in:
2026-11-16 16:17:31 +08:00
parent 58b3dedb2a
commit 50a8ae2e27
19 changed files with 444 additions and 192 deletions
+11 -9
View File
@@ -34,6 +34,7 @@ from euniv.client import (
_load_cookies,
as_uuid,
compact_id,
guard_https,
play_page_params,
study_progress_fields,
)
@@ -665,14 +666,12 @@ class HoursWatcher:
target: int,
user_stop: asyncio.Event,
interval: float = _HOURS_REFRESH_SECONDS,
source: str = "api",
) -> None:
self.session = session
self.employee_id = employee_id
self.target = target
self.user_stop = user_stop
self.interval = interval
self.source = source if source in ("api", "history") else "api"
self._lock = asyncio.Lock()
self.reached = False
from euniv.study_window import month_key
@@ -764,6 +763,7 @@ class StudySession:
timeout=30,
follow_redirects=True,
headers={"User-Agent": USER_AGENT},
event_hooks={"request": [guard_https]},
)
_load_cookies(self._client, self._initial_cookies)
self._proxy_lock = asyncio.Lock()
@@ -780,7 +780,7 @@ class StudySession:
if not self._use_pool:
return False
from euniv.proxy import async_httpx_client, parse_proxy
from euniv.proxy_pool import MAX_SWITCHES, acquire, mark_failed
from euniv.proxy_pool import MAX_SWITCHES, acquire, retire_if_dead
if self._proxy_lock is None:
self._proxy_lock = asyncio.Lock()
@@ -790,8 +790,10 @@ class StudySession:
return True
if self._switches >= MAX_SWITCHES:
return False
dead = await asyncio.to_thread(retire_if_dead, self._employee_id, failed)
if not dead:
return True
self._switches += 1
await asyncio.to_thread(mark_failed, self._employee_id, failed)
nxt = await asyncio.to_thread(acquire, self._employee_id)
parsed = parse_proxy(nxt)
if parsed == failed:
@@ -801,6 +803,7 @@ class StudySession:
timeout=30,
follow_redirects=True,
headers={"User-Agent": USER_AGENT},
event_hooks={"request": [guard_https]},
)
cookies = self._initial_cookies
if self._client is not None:
@@ -1454,7 +1457,7 @@ def _prepare_session(employee_id: str, password: str,
use_pool: bool = False
) -> tuple[str, str, str, list[tuple[str, str, str, str]], str | None, str]:
"""同步:恢复会话并导出 cookies。最后一项是 expired 或 network。"""
from euniv.proxy_pool import MAX_SWITCHES, acquire, mark_failed
from euniv.proxy_pool import MAX_SWITCHES, acquire, retire_if_dead
current = proxy
last_reason = "network"
@@ -1477,9 +1480,8 @@ def _prepare_session(employee_id: str, password: str,
except Exception as exc:
log.warning("用户 %s 准备会话失败: %s", employee_id, exc)
if use_pool and current and is_proxy_failure(exc):
mark_failed(employee_id, current, str(exc)[:200])
current = acquire(employee_id)
last_reason = "network"
if retire_if_dead(employee_id, current, str(exc)[:200]):
current = acquire(employee_id)
continue
last_reason = "expired" if isinstance(exc, SessionExpired) else "network"
return "", "", "", [], current, last_reason
@@ -1748,7 +1750,7 @@ class AutoStudyWorker:
_set_user_status(employee_id, state="已停止")
return
_set_user_status(employee_id, state="学习中")
hours = HoursWatcher(session, employee_id, target, user_stop, source=hours_source)
hours = HoursWatcher(session, employee_id, target, user_stop)
if await hours.refresh():
return
ticker = asyncio.create_task(hours.ticker(self._async_stop))