fix(fulfillment): 为商品能力全局补扫保留队列槽位
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# 直播账号运营后台
|
# 直播账号运营后台
|
||||||
|
|
||||||
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.10)。
|
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.11)。
|
||||||
|
|
||||||
## 能做什么
|
## 能做什么
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "live-hub-py"
|
name = "live-hub-py"
|
||||||
version = "0.4.10"
|
version = "0.4.11"
|
||||||
description = "直播账号运营 Web 后台"
|
description = "直播账号运营 Web 后台"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12,<3.13"
|
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]
|
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):
|
def test_refresh_ignores_tasks_before_match_cutoff(db):
|
||||||
db.add(
|
db.add(
|
||||||
PlatformFulfillmentSetting(
|
PlatformFulfillmentSetting(
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "live-hub-py"
|
name = "live-hub-py"
|
||||||
version = "0.4.10"
|
version = "0.4.11"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "alembic" },
|
{ name = "alembic" },
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ from ...platform_fulfillment.account_selector import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
JOB_KEY = "account_capability_refresh"
|
JOB_KEY = "account_capability_refresh"
|
||||||
|
DEFAULT_BACKFILL_RESERVED_SLOTS = 8
|
||||||
|
|
||||||
|
|
||||||
def _pending_demand_rows(
|
def _pending_demand_rows(
|
||||||
@@ -125,27 +126,30 @@ def _refresh_candidates(
|
|||||||
100,
|
100,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
backfill_reserved = min(
|
||||||
|
DEFAULT_BACKFILL_RESERVED_SLOTS,
|
||||||
|
max(0, batch // 4),
|
||||||
|
)
|
||||||
demand_candidates = (
|
demand_candidates = (
|
||||||
capability_refresh_candidate_accounts(
|
capability_refresh_candidate_accounts(
|
||||||
db,
|
db,
|
||||||
commodity_ids=commodity_ids,
|
commodity_ids=commodity_ids,
|
||||||
scope="elite",
|
scope="elite",
|
||||||
limit=batch,
|
limit=batch - backfill_reserved,
|
||||||
now=moment,
|
now=moment,
|
||||||
)
|
)
|
||||||
if commodity_ids
|
if commodity_ids and batch > backfill_reserved
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
demand_ids = {int(account.id) for account in demand_candidates}
|
demand_ids = {int(account.id) for account in demand_candidates}
|
||||||
remaining = batch - len(demand_candidates)
|
|
||||||
backfill_candidates = (
|
backfill_candidates = (
|
||||||
storehome_refresh_candidate_accounts(
|
storehome_refresh_candidate_accounts(
|
||||||
db,
|
db,
|
||||||
limit=remaining,
|
limit=batch - len(demand_candidates),
|
||||||
now=moment,
|
now=moment,
|
||||||
exclude_account_ids=tuple(demand_ids),
|
exclude_account_ids=tuple(demand_ids),
|
||||||
)
|
)
|
||||||
if remaining > 0
|
if batch > len(demand_candidates)
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
accounts = [*demand_candidates, *backfill_candidates]
|
accounts = [*demand_candidates, *backfill_candidates]
|
||||||
|
|||||||
Reference in New Issue
Block a user