refactor(douyu): 统一账号准入与本地查询链路

This commit is contained in:
yml
2026-11-22 19:31:32 +08:00
parent e652d30283
commit d78437c6ac
14 changed files with 592 additions and 548 deletions
@@ -10,6 +10,7 @@ from web.backend.models import (
AccountLease,
AccountWorkItem,
AutomationJob,
PlatformFulfillmentSetting,
PlatformFulfillmentTask,
User,
)
@@ -125,6 +126,68 @@ def test_no_pending_task_means_no_refresh(db):
assert job.build_select_query(db, automation_job, NOW).all() == []
def test_refresh_ignores_tasks_before_match_cutoff(db):
db.add(
PlatformFulfillmentSetting(
id=1,
lease_duration_minutes=None,
order_match_started_at=NOW - timedelta(days=1),
)
)
db.add_all(
[
PlatformFulfillmentTask(
source_system="order_site",
source_order_id="old",
source_order_item_id="old",
internal_sku_key="old-skin",
commodity_id="OLD",
execution_status="ready",
binding_status="not_started",
exchange_status="not_started",
paid_at=NOW - timedelta(days=2),
),
PlatformFulfillmentTask(
source_system="order_site",
source_order_id="new",
source_order_item_id="new",
internal_sku_key="new-skin",
commodity_id="NEW",
execution_status="ready",
binding_status="not_started",
exchange_status="not_started",
paid_at=NOW,
),
]
)
old_account = _account(db, "cap-cutoff-old")
new_account = _account(db, "cap-cutoff-new")
_state(
db,
old_account,
commodity_id="OLD",
valid_until=NOW - timedelta(minutes=1),
)
_state(
db,
new_account,
commodity_id="NEW",
valid_until=NOW - timedelta(minutes=1),
)
db.commit()
automation_job = AutomationJob(
key=job.JOB_KEY,
title="履约商品能力补充刷新",
interval_seconds=3600,
batch_size=10,
concurrency=3,
)
selected = job.build_select_query(db, automation_job, NOW).all()
assert [row.id for row in selected] == [new_account.id]
def test_run_enqueues_stale_accounts_without_external_query(db):
db.add(
PlatformFulfillmentTask(