fix(fulfillment): 队列满载时仍保留全局能力补扫
This commit is contained in:
@@ -195,7 +195,8 @@ def test_demand_refresh_runs_before_global_backfill(db):
|
||||
|
||||
|
||||
def test_busy_demand_keeps_reserved_backfill_slots(db, monkeypatch):
|
||||
monkeypatch.setenv("ACCOUNT_ORDER_QUEUE_TARGET_PENDING", "4")
|
||||
monkeypatch.setenv("ACCOUNT_ORDER_QUEUE_TARGET_PENDING", "3")
|
||||
monkeypatch.setenv("ACCOUNT_CAPABILITY_BACKFILL_RESERVED_SLOTS", "1")
|
||||
db.add(
|
||||
PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
@@ -464,6 +465,45 @@ def test_refresh_stops_at_queue_target(db, monkeypatch):
|
||||
assert db.query(AccountWorkItem).count() == 1
|
||||
|
||||
|
||||
def test_full_queue_still_allows_reserved_global_backfill(db, monkeypatch):
|
||||
monkeypatch.setenv("ACCOUNT_ORDER_QUEUE_TARGET_PENDING", "1")
|
||||
monkeypatch.setenv("ACCOUNT_CAPABILITY_BACKFILL_RESERVED_SLOTS", "1")
|
||||
active = _account(db, "cap-full-queue-active")
|
||||
backfill = _account(db, "cap-full-queue-backfill")
|
||||
_state(db, active, valid_until=NOW - timedelta(minutes=1))
|
||||
_state(db, backfill, commodity_id="OTHER", valid_until=NOW - timedelta(minutes=1))
|
||||
db.add(
|
||||
AccountWorkItem(
|
||||
account_id=active.id,
|
||||
work_type="storehome_sync",
|
||||
priority=10,
|
||||
status="pending",
|
||||
due_at=NOW,
|
||||
dedupe_key=f"storehome_sync:{active.id}",
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
automation_job = AutomationJob(
|
||||
key=job.JOB_KEY,
|
||||
title="履约商品能力补充刷新",
|
||||
interval_seconds=3600,
|
||||
batch_size=10,
|
||||
concurrency=3,
|
||||
)
|
||||
|
||||
result = job.run_account_capability_refresh(db, automation_job)
|
||||
|
||||
work = (
|
||||
db.query(AccountWorkItem)
|
||||
.filter_by(account_id=backfill.id, work_type="storehome_sync")
|
||||
.one()
|
||||
)
|
||||
assert result["scanned"] == 1
|
||||
assert result["detail"]["headroom"] == 0
|
||||
assert result["detail"]["backfill_reserved"] == 1
|
||||
assert work.priority == 30
|
||||
|
||||
|
||||
def test_default_enabled_job_is_created_enabled(db, monkeypatch):
|
||||
from web.backend.services.automation import scheduler
|
||||
|
||||
|
||||
Reference in New Issue
Block a user