feat(douyu): 接入重登工作队列与平台状态观测
This commit is contained in:
@@ -9,17 +9,20 @@ from web.backend.models import (
|
||||
AccountCommodityState,
|
||||
AccountLease,
|
||||
AccountSupplyTarget,
|
||||
AccountSyncState,
|
||||
AccountWorkItem,
|
||||
User,
|
||||
)
|
||||
from web.backend.routers.douyu import create_supply_target, list_supply_targets
|
||||
from web.backend.schemas import DouyuSupplyTargetUpsert
|
||||
from web.backend.services.account_observability import account_platform_status
|
||||
from web.backend.services.account_supply_service import (
|
||||
VALUE_HIGH,
|
||||
enqueue_supply_replenishment,
|
||||
evaluate_supply_target,
|
||||
upsert_supply_target,
|
||||
)
|
||||
from web.backend.services.account_work_queue import enqueue_account_work
|
||||
|
||||
NOW = datetime.now(UTC).replace(microsecond=0)
|
||||
|
||||
@@ -191,3 +194,47 @@ def test_supply_target_configuration_route_returns_inventory(db):
|
||||
assert created.covered_shortage == 12
|
||||
assert listed[0].id == created.id
|
||||
assert listed[0].needs_replenishment is True
|
||||
|
||||
|
||||
def test_account_platform_status_aggregates_queue_sync_and_supply(db):
|
||||
account = _account("platform-status", points=400)
|
||||
account.ck_expected_expires_at = NOW + timedelta(hours=12)
|
||||
db.add(account)
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
_state(account),
|
||||
AccountSyncState(
|
||||
account_id=account.id,
|
||||
platform="douyu",
|
||||
domain="storehome",
|
||||
status="success",
|
||||
last_success_at=NOW,
|
||||
valid_until=NOW + timedelta(hours=1),
|
||||
),
|
||||
AccountSupplyTarget(
|
||||
platform="douyu",
|
||||
scope="elite",
|
||||
commodity_id="C",
|
||||
value_class=VALUE_HIGH,
|
||||
target_covered=2,
|
||||
target_available=2,
|
||||
target_allocatable=1,
|
||||
),
|
||||
]
|
||||
)
|
||||
enqueue_account_work(
|
||||
db,
|
||||
account_id=account.id,
|
||||
work_type="login_relogin",
|
||||
)
|
||||
db.commit()
|
||||
|
||||
status = account_platform_status(db, now=NOW)
|
||||
|
||||
assert status["accounts"]["ck_valid"] == 1
|
||||
assert status["accounts"]["ck_expiring_24h"] == 1
|
||||
assert status["work_queue"]["login_relogin"]["pending"] == 1
|
||||
assert status["sync_domains"]["storehome"]["fresh"] == 1
|
||||
assert status["commodities"]["fresh_available"] == 1
|
||||
assert status["supply_targets"][0]["covered_shortage"] == 1
|
||||
|
||||
Reference in New Issue
Block a user