feat(douyu): 接入重登工作队列与平台状态观测

This commit is contained in:
yml
2026-11-21 21:58:31 +08:00
parent e178a393e4
commit 3b2d4f89fc
8 changed files with 456 additions and 5 deletions
+68
View File
@@ -21,8 +21,11 @@ from web.backend.services.account_sync_service import (
sync_storehome_snapshot,
)
from web.backend.services.account_work_queue import (
claim_account_work,
complete_account_work,
enqueue_account_work,
fail_account_work_type,
reschedule_account_work_type,
)
from web.backend.services.automation.jobs import ck_health
from web.backend.services.douyu_account_state import DouyuLiveAccountState
@@ -175,6 +178,71 @@ def test_account_work_queue_deduplicates_only_active_items(db):
assert db.query(AccountWorkItem).count() == 2
def test_account_work_claim_can_be_scoped_for_relogin(db):
first = _account("relogin-scope-a")
second = _account("relogin-scope-b")
db.add_all([first, second])
db.commit()
for account in (first, second):
enqueue_account_work(
db,
account_id=account.id,
work_type="login_relogin",
max_attempts=20,
)
db.commit()
claimed = claim_account_work(
db,
work_types=("login_relogin",),
account_ids=(first.id,),
limit=10,
)
assert [item.account_id for item in claimed] == [first.id]
assert claimed[0].attempt_count == 1
assert claimed[0].max_attempts == 20
def test_relogin_work_reschedules_then_closes_for_manual(db):
account = _account("relogin-work-state")
db.add(account)
db.commit()
enqueue_account_work(
db,
account_id=account.id,
work_type="login_relogin",
max_attempts=20,
)
db.commit()
item = claim_account_work(
db,
work_types=("login_relogin",),
account_ids=(account.id,),
limit=1,
)[0]
retry_at = datetime.now(UTC) + timedelta(hours=1)
reschedule_account_work_type(
db,
account_id=account.id,
work_type="login_relogin",
due_at=retry_at,
reason="验证码失败",
)
assert item.status == "pending"
assert item.due_at == retry_at.replace(microsecond=0)
fail_account_work_type(
db,
account_id=account.id,
work_type="login_relogin",
reason="转人工",
)
assert item.status == "failed"
assert item.last_error == "转人工"
def test_ck_verdict_updates_lifecycle_and_moves_relogin_work(db):
issued_at = datetime.now(UTC) - timedelta(days=7, hours=9)
account = _account("ck-lifecycle", cookie_updated_at=issued_at)