fix: 评估任务正在取工参时补取任务一分钟后再来,不用等定时检查;工作区没就绪时把页面文字记进日志

This commit is contained in:
2026-11-12 12:43:03 +08:00
parent 3a7a5b39b4
commit 1c1ff6a0af
6 changed files with 54 additions and 11 deletions
+12 -5
View File
@@ -33,6 +33,7 @@ from app.nqi.opencode import OpenCode
logger = logging.getLogger("decom")
TASK = "decom_gongcan_sync"
WAIT_SECONDS = 60
_SNAPSHOT = GongcanSnapshot.__table__
@@ -85,21 +86,27 @@ def execute_sync(city: str) -> None:
except (GongcanError, NqiError) as exc:
logger.info("工参缓存 %s 这次没取成:%s", city, exc)
return
if not remaining:
if fetched is not None:
logger.info("工参缓存 %s 已补 %s,已补齐", city, fetched)
return
if fetched is None:
# 评估任务正在取这个地市的某一份,或刚失败还在冷却:过一会儿再来,不等定时检查。
if has_valid_account():
request_sync(city, delay=WAIT_SECONDS)
return
logger.info("工参缓存 %s 已补 %s,还缺 %s 周", city, fetched, remaining)
if remaining:
request_sync(city)
request_sync(city)
def request_sync(city: str) -> bool:
"""排一个补取任务;这个地市已经有一个在排队时不重复排。演示模式和没有队列时不排。"""
def request_sync(city: str, *, delay: int = 0) -> bool:
"""排一个补取任务,delay 秒后执行;这个地市已经有一个在排队时不重复排。演示模式和没有队列时不排。"""
name = short_city(city)
if not name or not postgres_conninfo() or os.environ.get("DECOM_EVAL_SOURCE", "").strip().lower() == "mock":
return False
from app.tasks.queue import defer
return defer(TASK, queueing_lock=f"gongcan-sync:{name}", city=name)
return defer(TASK, queueing_lock=f"gongcan-sync:{name}", delay=delay, city=name)
def request_missing() -> None: