fix(fulfillment): 优先刷新联合皮肤全资格账号

This commit is contained in:
yml
2026-11-28 21:20:07 +08:00
parent 5d54954762
commit ab49def623
6 changed files with 162 additions and 9 deletions
@@ -17,6 +17,7 @@ from web.backend.models import (
)
from web.backend.services.automation.jobs import account_capability_refresh as job
from web.backend.services.automation.scheduler import JobSpec, ensure_jobs, register_job
from web.backend.services.platform_fulfillment.policy import default_allocation_policy
NOW = datetime.now(UTC).replace(microsecond=0)
@@ -504,6 +505,91 @@ def test_full_queue_still_allows_reserved_global_backfill(db, monkeypatch):
assert work.priority == 30
def test_global_backfill_prefers_known_full_bundle_accounts(db, monkeypatch):
monkeypatch.setenv("ACCOUNT_ORDER_QUEUE_TARGET_PENDING", "1")
monkeypatch.setenv("ACCOUNT_CAPABILITY_BACKFILL_RESERVED_SLOTS", "1")
db.add(
PlatformFulfillmentSetting(
id=1,
allocation_policy_json=default_allocation_policy(),
)
)
db.add(
PlatformFulfillmentTask(
source_system="order_site",
source_order_id="bundle-demand",
source_order_item_id="bundle-demand",
internal_sku_key="skin",
commodity_id="20260120QYOOB_bag412",
target_platform="douyu",
scope="elite",
execution_status="ready",
binding_status="not_started",
exchange_status="not_started",
paid_at=NOW,
)
)
active = _account(db, "cap-bundle-queue-active")
full = _account(db, "cap-bundle-full")
partial = _account(db, "cap-bundle-partial")
for commodity_id in (
"20260120QYOOB_bag412",
"20260120QYOOB_bag413",
"20260120QYOOB_bag414",
):
_state(
db,
full,
commodity_id=commodity_id,
valid_until=NOW - timedelta(minutes=1),
)
for commodity_id in (
"20260120QYOOB_bag412",
"20260120QYOOB_bag413",
):
_state(
db,
partial,
commodity_id=commodity_id,
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)
queued_ids = {
int(account_id)
for (account_id,) in (
db.query(AccountWorkItem.account_id)
.filter(
AccountWorkItem.work_type == "storehome_sync",
AccountWorkItem.priority == 30,
)
.all()
)
}
assert result["detail"]["backfill_refresh"] == 1
assert queued_ids == {full.id}
assert partial.id not in queued_ids
def test_default_enabled_job_is_created_enabled(db, monkeypatch):
from web.backend.services.automation import scheduler