feat(douyu): 建立账号同步队列与供给库存
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""按直播履约需求刷新账号商品能力。
|
||||
"""按直播履约需求把过期商品能力账号送入内部同步队列。
|
||||
|
||||
全量资料补全仍由 ``account_overview_refresh`` 负责;本作业只处理“有 pending
|
||||
任务、但对应商品能力快照已经过期”的账号,避免为了秒匹配把两万多个账号
|
||||
无条件轮询一遍。
|
||||
本作业只做本地候选筛选,不直接请求官网。真正的 ``storehome`` 查询由
|
||||
``account_sync_queue`` 作业在独立执行槽中低并发消费,避免补货查询抢占
|
||||
履约实时复核、登录或批量任务的执行资源。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -21,8 +21,9 @@ from ....models import (
|
||||
PlatformFulfillmentTask,
|
||||
)
|
||||
from ...account_lifecycle import MANUAL_STATES
|
||||
from ...account_sync_runner import WORK_STOREHOME_SYNC
|
||||
from ...account_work_queue import enqueue_account_work
|
||||
from ...douyu_service import cookie_operable_filter
|
||||
from .account_overview_refresh import run_refresh_for_accounts
|
||||
|
||||
JOB_KEY = "account_capability_refresh"
|
||||
|
||||
@@ -94,18 +95,29 @@ def run_account_capability_refresh(
|
||||
) -> dict[str, Any]:
|
||||
now = datetime.now(UTC)
|
||||
accounts = build_select_query(db, job, now).all()
|
||||
return run_refresh_for_accounts(
|
||||
db,
|
||||
job,
|
||||
accounts,
|
||||
now=now,
|
||||
# 精确剩余量要完整评估 accounts × commodity EXISTS,生产实测单次约
|
||||
# 1.3 秒、扫描 38 万行;它只用于展示,直接省略,避免每轮制造慢查询。
|
||||
remaining_count=None,
|
||||
source="capability_demand_refresh",
|
||||
log_label="capability",
|
||||
empty_message="当前履约商品没有到期待刷新的账号能力",
|
||||
)
|
||||
for account in accounts:
|
||||
enqueue_account_work(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
work_type=WORK_STOREHOME_SYNC,
|
||||
priority=40,
|
||||
reason="履约商品能力过期,等待补货刷新",
|
||||
due_at=now,
|
||||
)
|
||||
db.commit()
|
||||
queued = len(accounts)
|
||||
return {
|
||||
"scanned": len(accounts),
|
||||
"success": queued,
|
||||
"invalid": 0,
|
||||
"skipped": 0,
|
||||
"message": (
|
||||
f"本轮筛选 {len(accounts)} 个到期账号,新入队 {queued} 个"
|
||||
if accounts
|
||||
else "当前履约商品没有到期待刷新的账号能力"
|
||||
),
|
||||
"detail": {"queued": queued},
|
||||
}
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
||||
Reference in New Issue
Block a user