fix(fulfillment): 为商品能力全局补扫保留队列槽位
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user