feat: 工参每周一一份并提前缓存,登录后自动补缺;评估按周一取工参,指标等平台同步三天后再查

- 工参从 2024-01-01 起每周一一份,排队任务一次补一份,新的周先补;一个地市同时只取一份
- 大数据平台账号登录成功后排补取,排队进程每 10 分钟检查缺的周;排队进程重启时放开没取完的快照
- 拆除前工参用拆除日上一周的周一,拆除后用当周的周一;待拆小区不参与周边站和指标匹配
- 一周的指标等周日过后第 3 天才查,没到时间在结果说明里写明哪天之后有数据
- AI 工作区没就绪时开通接口返回 200,改为等待重试,最多 150 秒
- 排任务加锁,避免多个线程同时排时用到已关闭的连接池
- 运行面板显示各地市工参缓存进度
This commit is contained in:
2026-11-12 12:31:03 +08:00
parent 452b01498f
commit 3a7a5b39b4
20 changed files with 814 additions and 180 deletions
+11 -2
View File
@@ -18,7 +18,8 @@ class AccountUnavailable(Exception):
self.invalid = invalid
def borrow_account(exclude: set[int] | None = None) -> tuple[int, list] | None:
def borrow_account(exclude: set[int] | None = None, prefer_city: str = "") -> tuple[int, list] | None:
"""prefer_city 给出时,先用这个地市的账号,没有再用别的。"""
skipped = exclude or set()
with _lock:
with session_scope() as session:
@@ -32,7 +33,10 @@ def borrow_account(exclude: set[int] | None = None) -> tuple[int, list] | None:
NqiAccount.id,
)
).all()
account = next((row for row in rows if row.id not in skipped and row.cookies), None)
usable = [row for row in rows if row.id not in skipped and row.cookies]
if prefer_city:
usable.sort(key=lambda row: not (row.city_name or "").startswith(prefer_city))
account = usable[0] if usable else None
if account is None:
return None
account.active_tasks += 1
@@ -53,6 +57,11 @@ def release_account(account_id: int, *, invalid: bool = False) -> None:
account.credential_valid = False
def has_valid_account() -> bool:
with session_scope() as session:
return session.scalar(select(NqiAccount.id).where(NqiAccount.credential_valid.is_(True)).limit(1)) is not None
def reset_active_tasks() -> None:
with session_scope() as session:
session.execute(update(NqiAccount).values(active_tasks=0))