fix(fulfillment): 为商品能力全局补扫保留队列槽位

This commit is contained in:
yml
2026-11-28 21:04:19 +08:00
parent 7ca011c14e
commit 371027d730
5 changed files with 61 additions and 8 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# 直播账号运营后台
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.10)。
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.11)。
## 能做什么
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "live-hub-py"
version = "0.4.10"
version = "0.4.11"
description = "直播账号运营 Web 后台"
readme = "README.md"
requires-python = ">=3.12,<3.13"
@@ -194,6 +194,55 @@ def test_demand_refresh_runs_before_global_backfill(db):
assert [row.id for row in selected] == [demand.id, backfill.id]
def test_busy_demand_keeps_reserved_backfill_slots(db, monkeypatch):
monkeypatch.setenv("ACCOUNT_ORDER_QUEUE_TARGET_PENDING", "4")
db.add(
PlatformFulfillmentTask(
source_system="order_site",
source_order_id="reserve-demand",
source_order_item_id="reserve-demand",
internal_sku_key="skin",
commodity_id="C",
execution_status="ready",
binding_status="not_started",
exchange_status="not_started",
paid_at=NOW,
)
)
demand_accounts = [_account(db, f"cap-demand-{index}") for index in range(5)]
backfill = _account(db, "cap-reserved-backfill")
for account in demand_accounts:
_state(db, account, commodity_id="C", valid_until=NOW - timedelta(minutes=1))
_state(
db,
backfill,
commodity_id="OTHER",
valid_until=NOW - timedelta(minutes=1),
)
db.commit()
automation_job = AutomationJob(
key=job.JOB_KEY,
title="履约商品能力补充刷新",
interval_seconds=3600,
batch_size=4,
concurrency=3,
)
result = job.run_account_capability_refresh(db, automation_job)
assert result["scanned"] == 4
assert result["detail"]["demand_refresh"] == 3
assert result["detail"]["backfill_refresh"] == 1
works = (
db.query(AccountWorkItem)
.filter(AccountWorkItem.work_type == "storehome_sync")
.order_by(AccountWorkItem.priority.asc())
.all()
)
assert len([work for work in works if work.priority == 10]) == 3
assert len([work for work in works if work.priority == 30]) == 1
def test_refresh_ignores_tasks_before_match_cutoff(db):
db.add(
PlatformFulfillmentSetting(
Generated
+1 -1
View File
@@ -381,7 +381,7 @@ wheels = [
[[package]]
name = "live-hub-py"
version = "0.4.10"
version = "0.4.11"
source = { editable = "." }
dependencies = [
{ name = "alembic" },
@@ -33,6 +33,7 @@ from ...platform_fulfillment.account_selector import (
)
JOB_KEY = "account_capability_refresh"
DEFAULT_BACKFILL_RESERVED_SLOTS = 8
def _pending_demand_rows(
@@ -125,27 +126,30 @@ def _refresh_candidates(
100,
),
)
backfill_reserved = min(
DEFAULT_BACKFILL_RESERVED_SLOTS,
max(0, batch // 4),
)
demand_candidates = (
capability_refresh_candidate_accounts(
db,
commodity_ids=commodity_ids,
scope="elite",
limit=batch,
limit=batch - backfill_reserved,
now=moment,
)
if commodity_ids
if commodity_ids and batch > backfill_reserved
else []
)
demand_ids = {int(account.id) for account in demand_candidates}
remaining = batch - len(demand_candidates)
backfill_candidates = (
storehome_refresh_candidate_accounts(
db,
limit=remaining,
limit=batch - len(demand_candidates),
now=moment,
exclude_account_ids=tuple(demand_ids),
)
if remaining > 0
if batch > len(demand_candidates)
else []
)
accounts = [*demand_candidates, *backfill_candidates]