fix: 续期发现登录失效时暂停任务
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from app.platform.client import NqiAuthError, NqiError
|
||||
from app.platform.sessions import remember_account
|
||||
from app.shared.state import state
|
||||
|
||||
@@ -14,9 +15,16 @@ INTERVAL_SECONDS = 180
|
||||
|
||||
async def refresh_saved_session() -> None:
|
||||
client = state.client
|
||||
if client is None or state.user is None:
|
||||
if client is None or state.user is None or state.expired:
|
||||
return
|
||||
try:
|
||||
refreshed = await client.touch_session()
|
||||
except NqiAuthError as exc:
|
||||
state.on_session_expired(str(exc) or "登录已失效,请重新登录")
|
||||
return
|
||||
except NqiError as exc:
|
||||
logger.info("登录续期未完成: %s", exc)
|
||||
return
|
||||
refreshed = await client.touch_session()
|
||||
state.user = refreshed
|
||||
await remember_account(refreshed, client.export_cookies())
|
||||
|
||||
@@ -26,5 +34,7 @@ async def session_keepalive() -> None:
|
||||
await asyncio.sleep(INTERVAL_SECONDS)
|
||||
try:
|
||||
await refresh_saved_session()
|
||||
except NqiAuthError as exc:
|
||||
state.on_session_expired(str(exc) or "登录已失效,请重新登录")
|
||||
except Exception as exc:
|
||||
logger.info("登录续期未完成: %s", exc)
|
||||
|
||||
Reference in New Issue
Block a user