feat: 工参每周一一份并提前缓存,登录后自动补缺;评估按周一取工参,指标等平台同步三天后再查
- 工参从 2024-01-01 起每周一一份,排队任务一次补一份,新的周先补;一个地市同时只取一份 - 大数据平台账号登录成功后排补取,排队进程每 10 分钟检查缺的周;排队进程重启时放开没取完的快照 - 拆除前工参用拆除日上一周的周一,拆除后用当周的周一;待拆小区不参与周边站和指标匹配 - 一周的指标等周日过后第 3 天才查,没到时间在结果说明里写明哪天之后有数据 - AI 工作区没就绪时开通接口返回 200,改为等待重试,最多 150 秒 - 排任务加锁,避免多个线程同时排时用到已关闭的连接池 - 运行面板显示各地市工参缓存进度
This commit is contained in:
@@ -5,10 +5,12 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import contextlib
|
||||
import logging
|
||||
import threading
|
||||
|
||||
import procrastinate
|
||||
from procrastinate.worker import Worker
|
||||
|
||||
from app.collect.gongcan_sync import execute_sync
|
||||
from app.config import postgres_conninfo
|
||||
from app.evaluate.runner import execute_task, finalize_job
|
||||
from app.tasks.runner import current_concurrency, execute_collection
|
||||
@@ -18,6 +20,7 @@ logger = logging.getLogger("decom")
|
||||
conninfo = postgres_conninfo() or "postgresql://invalid"
|
||||
queue = procrastinate.App(connector=procrastinate.PsycopgConnector(conninfo=conninfo))
|
||||
defer_queue = procrastinate.App(connector=procrastinate.PsycopgConnector(conninfo=conninfo))
|
||||
_defer_lock = threading.Lock()
|
||||
|
||||
|
||||
@queue.task(name="decom_eval_task", queue="decom")
|
||||
@@ -35,11 +38,23 @@ def decom_collect(source_id: int, force: bool = False) -> None:
|
||||
execute_collection(source_id, force=force)
|
||||
|
||||
|
||||
def defer(name: str, **kwargs) -> None:
|
||||
@queue.task(name="decom_gongcan_sync", queue="decom")
|
||||
def decom_gongcan_sync(city: str) -> None:
|
||||
execute_sync(city)
|
||||
|
||||
|
||||
def defer(name: str, *, queueing_lock: str | None = None, **kwargs) -> bool:
|
||||
"""排一个任务。queueing_lock 相同的任务已有一个在排队时不再排,返回 False。"""
|
||||
# API 和 worker 是两个进程;worker 自己还会从后台线程提交采集任务。
|
||||
# 使用独立的同步连接,避免与 worker 持有的异步连接互相关闭。
|
||||
with defer_queue.open():
|
||||
defer_queue.configure_task(name, queue="decom").defer(**kwargs)
|
||||
# 几个线程会同时来排任务;连接池由先到的打开、退出时关闭,不加锁后到的会用到已关闭的池。
|
||||
options = {"queueing_lock": queueing_lock} if queueing_lock else {}
|
||||
with _defer_lock, defer_queue.open():
|
||||
try:
|
||||
defer_queue.configure_task(name, queue="decom", **options).defer(**kwargs)
|
||||
except procrastinate.exceptions.AlreadyEnqueued:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class DynamicGate:
|
||||
|
||||
Reference in New Issue
Block a user