feat: 工参每周一一份并提前缓存,登录后自动补缺;评估按周一取工参,指标等平台同步三天后再查
- 工参从 2024-01-01 起每周一一份,排队任务一次补一份,新的周先补;一个地市同时只取一份 - 大数据平台账号登录成功后排补取,排队进程每 10 分钟检查缺的周;排队进程重启时放开没取完的快照 - 拆除前工参用拆除日上一周的周一,拆除后用当周的周一;待拆小区不参与周边站和指标匹配 - 一周的指标等周日过后第 3 天才查,没到时间在结果说明里写明哪天之后有数据 - AI 工作区没就绪时开通接口返回 200,改为等待重试,最多 150 秒 - 排任务加锁,避免多个线程同时排时用到已关闭的连接池 - 运行面板显示各地市工参缓存进度
This commit is contained in:
+15
-1
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import logging
|
||||
import re
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
|
||||
@@ -15,6 +16,7 @@ from app.config import env_database, hosted, installed
|
||||
from app.install import InstallError, perform_install
|
||||
from app.db import get_session, session_scope
|
||||
from app.models import AppSetting, CollectionSource, NqiAccount, User, utcnow
|
||||
from app.collect.gongcan_sync import cache_status, request_sync
|
||||
from app.collect.schedule import next_run_at, parse_schedule
|
||||
from app.nqi.adhoc import TIME_MODES, catalog_tree, categories, search_by_field, table_fields, tables, time_window
|
||||
from app.nqi.client import NqiAuthError, NqiClient, NqiError
|
||||
@@ -22,6 +24,7 @@ from app.nqi.flows import drop, purge, remember, take
|
||||
from app.security import hash_password, issue_token, verify_password
|
||||
from app.tasks.runner import check_concurrency, check_refresh, enqueue_collection
|
||||
|
||||
logger = logging.getLogger("decom")
|
||||
router = APIRouter(prefix="/api")
|
||||
# 在响应发出前提交,客户端紧接着发出的请求才能读到刚写入的内容。
|
||||
db_session = Depends(get_session, scope="function")
|
||||
@@ -282,6 +285,9 @@ async def nqi_finish(body: dict) -> dict:
|
||||
account.credential_valid = adhoc_ready
|
||||
login_id = account.login_id
|
||||
name = account.user_name or account.login_id
|
||||
city = account.city_name
|
||||
if adhoc_ready:
|
||||
await asyncio.to_thread(_cache_gongcan, city)
|
||||
if purpose == "pool":
|
||||
return {"status": "ok"}
|
||||
return _token_for("nqi", login_id, "user", name)
|
||||
@@ -400,7 +406,7 @@ def update_user_password(user_id: int, body: dict, actor: Actor = Depends(curren
|
||||
def admin_dashboard(actor: Actor = Depends(current_actor), session: Session = db_session) -> dict:
|
||||
require_admin(actor)
|
||||
rows = session.scalars(select(NqiAccount)).all()
|
||||
return {"pool": _pool_dashboard(rows)}
|
||||
return {"pool": _pool_dashboard(rows), "gongcan": cache_status()}
|
||||
|
||||
|
||||
@router.get("/admin/pool")
|
||||
@@ -723,6 +729,14 @@ def _pool_dashboard(rows: list[NqiAccount]) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def _cache_gongcan(city: str) -> None:
|
||||
"""有新凭证了,补取这个地市缺的工参。排不上只记日志,不影响登录。"""
|
||||
try:
|
||||
request_sync(city)
|
||||
except Exception as exc:
|
||||
logger.info("登录后排工参补取未完成: %s", exc)
|
||||
|
||||
|
||||
def _save_pool(session: Session, user: dict, cookies: list) -> NqiAccount:
|
||||
login_id = str(user.get("loginId") or "").strip()
|
||||
if not login_id:
|
||||
|
||||
Reference in New Issue
Block a user