增强登录稳定性

This commit is contained in:
yml2213
2026-06-24 09:17:15 +08:00
parent 177ec42416
commit 7bb50a9bbf
4 changed files with 106 additions and 14 deletions
+16 -1
View File
@@ -68,6 +68,15 @@ class LoginBatchRunner:
def stop(self):
self._stop.set()
def _sleep_or_stop(self, seconds: float) -> bool:
"""可中断等待;返回 True 表示收到停止信号。"""
deadline = time.monotonic() + seconds
while time.monotonic() < deadline:
if self._stop.is_set():
return True
time.sleep(min(0.2, deadline - time.monotonic()))
return self._stop.is_set()
def _push_log(self, level: str, message: str):
if self.log_queue and self.loop:
asyncio.run_coroutine_threadsafe(
@@ -145,7 +154,12 @@ class LoginBatchRunner:
task.finished_at = datetime.now(timezone.utc)
worker_db.commit()
return
time.sleep(10)
if self._sleep_or_stop(10):
task.status = "error"
task.message = "任务已停止"
task.finished_at = datetime.now(timezone.utc)
worker_db.commit()
return
test_proxy = self._shared_proxy_manager.get_proxy()
if test_proxy:
self._shared_proxy_manager.release_proxy(test_proxy)
@@ -191,6 +205,7 @@ class LoginBatchRunner:
max_login_retries=self.max_login_retries,
max_total_time=self.max_total_time,
proxy_manager=self._shared_proxy_manager,
stop_event=self._stop,
)
result = loginer.login()