perf(douyu): 优化慢查询并修复供应商充值收口
This commit is contained in:
@@ -13,6 +13,7 @@ from web.backend.models import (
|
||||
User,
|
||||
)
|
||||
from web.backend.services.automation.jobs import account_capability_refresh as job
|
||||
from web.backend.services.automation.scheduler import JobSpec, ensure_jobs, register_job
|
||||
|
||||
NOW = datetime.now(UTC).replace(microsecond=0)
|
||||
|
||||
@@ -121,3 +122,68 @@ def test_no_pending_task_means_no_refresh(db):
|
||||
)
|
||||
|
||||
assert job.build_select_query(db, automation_job, NOW).all() == []
|
||||
|
||||
|
||||
def test_run_does_not_execute_exact_remaining_count(db, monkeypatch):
|
||||
db.add(
|
||||
PlatformFulfillmentTask(
|
||||
source_system="order_site",
|
||||
source_order_id="2",
|
||||
source_order_item_id="2",
|
||||
internal_sku_key="skin",
|
||||
commodity_id="C",
|
||||
execution_status="ready",
|
||||
binding_status="not_started",
|
||||
exchange_status="not_started",
|
||||
paid_at=NOW,
|
||||
)
|
||||
)
|
||||
stale = _account(db, "cap-run-stale")
|
||||
_state(db, stale, valid_until=NOW - timedelta(minutes=1))
|
||||
db.commit()
|
||||
automation_job = AutomationJob(
|
||||
key=job.JOB_KEY,
|
||||
title="履约商品能力补充刷新",
|
||||
interval_seconds=3600,
|
||||
batch_size=10,
|
||||
concurrency=3,
|
||||
)
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_run_refresh(_db, _job, accounts, **kwargs):
|
||||
captured["accounts"] = [row.id for row in accounts]
|
||||
captured["remaining_count"] = kwargs.get("remaining_count")
|
||||
return {"scanned": len(accounts)}
|
||||
|
||||
monkeypatch.setattr(job, "run_refresh_for_accounts", fake_run_refresh)
|
||||
|
||||
job.run_account_capability_refresh(db, automation_job)
|
||||
|
||||
assert captured["accounts"] == [stale.id]
|
||||
assert captured["remaining_count"] is None
|
||||
|
||||
|
||||
def test_default_enabled_job_is_created_enabled(db, monkeypatch):
|
||||
from web.backend.services.automation import scheduler
|
||||
|
||||
monkeypatch.setattr(scheduler, "_REGISTRY", {})
|
||||
register_job(
|
||||
JobSpec(
|
||||
key="retention-default-on",
|
||||
title="默认启用测试",
|
||||
interval_seconds=3600,
|
||||
batch_size=10,
|
||||
concurrency=1,
|
||||
run=lambda _db, _job: {"scanned": 0},
|
||||
default_enabled=True,
|
||||
)
|
||||
)
|
||||
|
||||
ensure_jobs(db)
|
||||
|
||||
row = (
|
||||
db.query(AutomationJob)
|
||||
.filter(AutomationJob.key == "retention-default-on")
|
||||
.one()
|
||||
)
|
||||
assert row.enabled is True
|
||||
|
||||
Reference in New Issue
Block a user