feat(douyu): unify account probes and lifecycle writes
Centralize Douyu client creation, CK session probing, identity refresh, role alias resolution, capability persistence, cache and batch throttling across collaboration, fulfillment, tasks and cookie management. Add the account-name copy action in the collaboration table.
This commit is contained in:
@@ -10,8 +10,8 @@ from core.douyu import DouyuActivityError
|
||||
|
||||
from ..database import SessionLocal
|
||||
from ..models import DouyuTask
|
||||
from .account_lifecycle import on_ck_verdict
|
||||
from .cookie_check_service import check_douyu_cookie
|
||||
from .douyu_account_probe import persist_probe_result, probe_session
|
||||
from .douyu_runner_bind import BindMixin
|
||||
from .douyu_runner_core import ( # noqa: F401 (douyu_batch_registry 供 routers 重导出)
|
||||
DouyuBatchRunnerCore,
|
||||
@@ -68,18 +68,42 @@ class DouyuBatchRunner(
|
||||
)
|
||||
return
|
||||
|
||||
cookie_check = check_douyu_cookie(cookie)
|
||||
cookie_check = probe_session(cookie, checker=check_douyu_cookie)
|
||||
ck_verdict = str(cookie_check["status"])
|
||||
# 执行前的这次检测同样要写结论、由好变坏记事件、重算状态。
|
||||
on_ck_verdict(
|
||||
persist_probe_result(
|
||||
worker_db,
|
||||
account,
|
||||
"valid" if cookie_check["valid"] else "invalid",
|
||||
detail=cookie_check,
|
||||
occurred_at=cookie_check["checked_at"],
|
||||
{
|
||||
"probe_id": f"task-preflight:{task.id}",
|
||||
"identity": {
|
||||
"uid": account.uid,
|
||||
"username": account.username,
|
||||
"nickname": (
|
||||
(cookie_check.get("detail") or {}).get("nickname") or ""
|
||||
),
|
||||
"nickname_source": "session",
|
||||
},
|
||||
"session": cookie_check,
|
||||
"elite": {},
|
||||
"eligibility": {},
|
||||
"roles": {},
|
||||
"gold": {},
|
||||
"goods": {},
|
||||
"errors": {},
|
||||
},
|
||||
source="douyu_task.preflight",
|
||||
record_event=False,
|
||||
commit=False,
|
||||
)
|
||||
worker_db.commit()
|
||||
if not cookie_check["valid"]:
|
||||
message = f"Cookie 已失效,请重新登录:{cookie_check['message']}"
|
||||
if ck_verdict != "valid":
|
||||
prefix = (
|
||||
"Cookie 已失效,请重新登录"
|
||||
if ck_verdict == "invalid"
|
||||
else "Cookie 状态无法确认"
|
||||
)
|
||||
message = f"{prefix}:{cookie_check['message']}"
|
||||
self._mark_task(worker_db, task, "failed", message)
|
||||
self._push_log(
|
||||
"warning", f"[{current}] {self._account_name(account)} {message}"
|
||||
|
||||
Reference in New Issue
Block a user