feat: 完善登录保持、栅格下载和任务调度
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""登录后定时访问门户接口,避免闲置导致凭证失效。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from app.platform.sessions import remember
|
||||
from app.shared.state import state
|
||||
|
||||
logger = logging.getLogger("nqi.auth")
|
||||
INTERVAL_SECONDS = 180
|
||||
|
||||
|
||||
async def refresh_saved_session() -> None:
|
||||
client = state.client
|
||||
if client is None or state.user is None:
|
||||
return
|
||||
refreshed = await client.touch_session()
|
||||
state.user = refreshed
|
||||
remember(refreshed, client.export_cookies())
|
||||
|
||||
|
||||
async def session_keepalive() -> None:
|
||||
while True:
|
||||
await asyncio.sleep(INTERVAL_SECONDS)
|
||||
try:
|
||||
await refresh_saved_session()
|
||||
except Exception as exc:
|
||||
logger.info("登录续期未完成: %s", exc)
|
||||
Reference in New Issue
Block a user