fix(automation): 修复账号供给补货队列饥饿
- 拆分订单补货和通用供给水位,供给保留独立 pending 配额 - 每批固定供给槽位,避免订单补货占满队列 - 只补覆盖/可兑换缺口,可分配缺口不再无效入队 - 重登工作超过 24h 自动转人工,清理待处理积压 - 补货阻塞告警和队列诊断信息 - 增加供给公平调度/过期清理回归测试
This commit is contained in:
@@ -17,12 +17,16 @@ from web.backend.services.account_sync_runner import (
|
||||
WORK_ESPORTS_SYNC,
|
||||
WORK_EXCHANGE_RECORDS_SYNC,
|
||||
WORK_STOREHOME_SYNC,
|
||||
claim_sync_work_batch,
|
||||
execute_account_work_item,
|
||||
run_account_sync_queue,
|
||||
)
|
||||
from web.backend.services.account_work_queue import (
|
||||
ORDER_REFRESH_REASON_PREFIX,
|
||||
SUPPLY_REASON_PREFIX,
|
||||
claim_account_work,
|
||||
enqueue_account_work,
|
||||
expire_stale_login_work,
|
||||
recover_running_account_work,
|
||||
)
|
||||
from web.backend.services.douyu_read_gateway import StorehomeSnapshot
|
||||
@@ -337,3 +341,65 @@ def test_restart_recovers_running_work(db):
|
||||
assert row.status == "pending"
|
||||
assert row.due_at <= datetime.now(UTC)
|
||||
assert "服务重启" in row.last_error
|
||||
|
||||
|
||||
def test_claim_sync_work_batch_reserves_supply_quota(db, monkeypatch):
|
||||
monkeypatch.setenv("ACCOUNT_SUPPLY_QUEUE_QUOTA", "5")
|
||||
moment = datetime.now(UTC).replace(microsecond=0)
|
||||
accounts = [_account(f"quota-{index}") for index in range(25)]
|
||||
db.add_all(accounts)
|
||||
db.flush()
|
||||
for account in accounts[:20]:
|
||||
enqueue_account_work(
|
||||
db,
|
||||
account_id=account.id,
|
||||
work_type=WORK_STOREHOME_SYNC,
|
||||
priority=10,
|
||||
reason=f"{ORDER_REFRESH_REASON_PREFIX} C",
|
||||
due_at=moment,
|
||||
)
|
||||
for account in accounts[20:]:
|
||||
enqueue_account_work(
|
||||
db,
|
||||
account_id=account.id,
|
||||
work_type=WORK_STOREHOME_SYNC,
|
||||
priority=35,
|
||||
reason=f"{SUPPLY_REASON_PREFIX} elite/all/high_value",
|
||||
due_at=moment,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
supply, normal = claim_sync_work_batch(db, limit=20, now=moment)
|
||||
|
||||
assert len(supply) == 5
|
||||
assert len(normal) == 15
|
||||
assert all(
|
||||
item.reason.startswith(SUPPLY_REASON_PREFIX) for item in supply
|
||||
)
|
||||
assert all(
|
||||
not item.reason.startswith(SUPPLY_REASON_PREFIX) for item in normal
|
||||
)
|
||||
|
||||
|
||||
def test_expire_stale_login_work(db):
|
||||
moment = datetime.now(UTC).replace(microsecond=0)
|
||||
account = _account("relogin-stale")
|
||||
db.add(account)
|
||||
db.flush()
|
||||
item = enqueue_account_work(
|
||||
db,
|
||||
account_id=account.id,
|
||||
work_type="login_relogin",
|
||||
priority=30,
|
||||
due_at=moment - timedelta(days=2),
|
||||
max_attempts=20,
|
||||
reason="CK 已判定失效,等待受预算控制的重登",
|
||||
)
|
||||
db.commit()
|
||||
|
||||
expired = expire_stale_login_work(db, now=moment, ttl_seconds=86400)
|
||||
|
||||
db.refresh(item)
|
||||
assert expired == 1
|
||||
assert item.status == "failed"
|
||||
assert "已转人工" in item.last_error
|
||||
|
||||
Reference in New Issue
Block a user