feat(fulfillment): 增加账号商品能力索引与生命周期事件

This commit is contained in:
yml
2026-11-18 19:30:59 +08:00
parent dc95d83b32
commit 667634a8df
35 changed files with 3076 additions and 82 deletions
@@ -124,3 +124,60 @@ def test_auto_allocator_schedules_retry_only_after_failed_allocation(db):
assert result == {"checked": 1, "allocated": 0, "failed": 1}
assert task.next_allocate_at is not None
assert task.next_allocate_at >= moment + timedelta(seconds=10)
def test_auto_allocator_prioritizes_oldest_paid_task_after_due_check(db):
actor = User(username="auto-fair-actor", password_hash="h", role="super_admin")
moment = datetime.now(UTC)
db.add(
PlatformFulfillmentSetting(
id=1,
lease_duration_minutes=None,
order_match_started_at=moment - timedelta(days=1),
)
)
older = PlatformFulfillmentTask(
source_system="order_site",
source_order_id="20",
source_order_item_id="20",
platform_order_id="AUTO-OLDER",
internal_sku_key="skin",
commodity_id="commodity-1",
execution_status="ready",
binding_status="not_started",
exchange_status="not_started",
paid_at=moment - timedelta(minutes=10),
next_allocate_at=moment,
updated_at=moment,
)
newer = PlatformFulfillmentTask(
source_system="order_site",
source_order_id="21",
source_order_item_id="21",
platform_order_id="AUTO-NEWER",
internal_sku_key="skin",
commodity_id="commodity-1",
execution_status="ready",
binding_status="not_started",
exchange_status="not_started",
paid_at=moment - timedelta(minutes=1),
next_allocate_at=moment,
updated_at=moment,
)
db.add_all([actor, older, newer])
db.commit()
calls: list[int] = []
with (
patch.object(auto_allocator.service, "_integration_actor", return_value=actor),
patch.object(
auto_allocator.service,
"allocate_task",
side_effect=lambda _db, *, task_id, current: (
calls.append(task_id) or {"task": {"account": {"id": 9}}}
),
),
):
auto_allocator.run_auto_allocation_once(db, limit=1, now=moment)
assert calls == [older.id]