perf(douyu): 优化慢查询并修复供应商充值收口
This commit is contained in:
@@ -114,6 +114,7 @@ def register_default_jobs() -> None:
|
||||
batch_size=2000,
|
||||
concurrency=1,
|
||||
run=run_douyu_tasks_retention,
|
||||
default_enabled=True,
|
||||
)
|
||||
)
|
||||
register_job(
|
||||
|
||||
@@ -84,14 +84,6 @@ def build_select_query(
|
||||
)
|
||||
|
||||
|
||||
def count_remaining(
|
||||
db: Session,
|
||||
*,
|
||||
now: datetime | None = None,
|
||||
) -> int:
|
||||
return _base_query(db, now or datetime.now(UTC)).count()
|
||||
|
||||
|
||||
def run_account_capability_refresh(
|
||||
db: Session,
|
||||
job: AutomationJob,
|
||||
@@ -103,7 +95,9 @@ def run_account_capability_refresh(
|
||||
job,
|
||||
accounts,
|
||||
now=now,
|
||||
remaining_count=count_remaining(db, now=now),
|
||||
# 精确剩余量要完整评估 accounts × commodity EXISTS,生产实测单次约
|
||||
# 1.3 秒、扫描 38 万行;它只用于展示,直接省略,避免每轮制造慢查询。
|
||||
remaining_count=None,
|
||||
source="capability_demand_refresh",
|
||||
log_label="capability",
|
||||
empty_message="当前履约商品没有到期待刷新的账号能力",
|
||||
@@ -113,6 +107,5 @@ def run_account_capability_refresh(
|
||||
__all__ = [
|
||||
"JOB_KEY",
|
||||
"build_select_query",
|
||||
"count_remaining",
|
||||
"run_account_capability_refresh",
|
||||
]
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
- 不删行、只删「过期的整行」:不做「把 result 清空保留行」这种半吊子操作,
|
||||
因为部分前端派生**明确要求 result 非空**,清空等于制造「有行但读不出状态」的
|
||||
更隐蔽的坏状态;
|
||||
- 作业**默认关闭**(`ensure_jobs` 建行时 enabled=False),由运维在页面上打开。
|
||||
- 作业**默认启用**(`ensure_jobs` 建行时 enabled=True),避免执行日志无限增长;
|
||||
运维仍可在页面上关闭。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
自动化按「渐进上线」推进,因此:
|
||||
|
||||
- 调度器总开关 ``AUTOMATION_ENABLED`` **默认关闭**;
|
||||
- 每个作业自己还有开关,**默认关闭**,在 ``/automation`` 页面打开;
|
||||
- 每个作业自己还有开关,**默认关闭**;少数维护型作业可通过
|
||||
``JobSpec.default_enabled`` 在首次建行时默认启用,之后仍完全尊重页面配置;
|
||||
- 作业状态全部落库(``automation_jobs`` / ``automation_runs``),进程重启不丢
|
||||
调度进度,也不会因为重启而重复跑一轮。
|
||||
|
||||
@@ -65,6 +66,8 @@ class JobSpec:
|
||||
#: **多久跑一次**(调度频率)。默认 5 分钟,与改动前的实际行为一致。
|
||||
#: ⚠️ 必须放在**有默认值**的位置(dataclass 不允许默认值字段排在无默认值之前)。
|
||||
run_interval_seconds: int = 300
|
||||
#: 新库首次创建作业行时是否默认启用。已有行永远尊重运维配置。
|
||||
default_enabled: bool = False
|
||||
|
||||
|
||||
_REGISTRY: dict[str, JobSpec] = {}
|
||||
@@ -120,7 +123,7 @@ def ensure_jobs(db: Session) -> None:
|
||||
AutomationJob(
|
||||
key=spec.key,
|
||||
title=spec.title,
|
||||
enabled=False,
|
||||
enabled=spec.default_enabled,
|
||||
interval_seconds=spec.interval_seconds,
|
||||
run_interval_seconds=spec.run_interval_seconds,
|
||||
batch_size=spec.batch_size,
|
||||
|
||||
Reference in New Issue
Block a user