refactor(douyu): 完成阶段5旧链路清理
This commit is contained in:
@@ -17,8 +17,9 @@ from sqlalchemy import and_, case, func, or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ....models import Account, AutomationJob
|
||||
from ...account_lifecycle import MANUAL_STATES, WORK_LOGIN_RELOGIN
|
||||
from ...account_lifecycle import WORK_LOGIN_RELOGIN
|
||||
from ...account_protection_service import load_protection_snapshot
|
||||
from ...account_query_filters import automation_account_filter
|
||||
from ...account_value import (
|
||||
HIGH_VALUE_TIER_MAX,
|
||||
high_value_recheck_seconds,
|
||||
@@ -35,7 +36,6 @@ from ...douyu_account_probe import (
|
||||
persist_probe_result,
|
||||
probe_session,
|
||||
)
|
||||
from ...douyu_service import cookie_holding_filter, cookie_operable_filter
|
||||
from ...task_runtime import TaskLane, submit
|
||||
|
||||
JOB_KEY = "ck_health"
|
||||
@@ -101,13 +101,11 @@ def _candidates_query(db: Session, job: AutomationJob, now: datetime):
|
||||
|
||||
query = (
|
||||
db.query(Account)
|
||||
.filter(cookie_operable_filter())
|
||||
.filter(Account.auto_managed.is_(True))
|
||||
.filter(automation_account_filter())
|
||||
# invalid 已进入自动重登队列,manual 已停止自动处理;普通 CK 探针
|
||||
# 再扫它们只会重复消耗官方请求,并掩盖真正需要发现的新失效。
|
||||
.filter(Account.ck_check_status.notin_(("invalid", "manual")))
|
||||
# 生命周期状态机:停用/归档的账号不参与任何自动化(见 account_lifecycle)。
|
||||
.filter(Account.status.notin_(MANUAL_STATES))
|
||||
.filter(due_filter)
|
||||
)
|
||||
if protected_ids:
|
||||
@@ -181,7 +179,7 @@ def run_ck_health(db: Session, job: AutomationJob) -> dict[str, Any]:
|
||||
if not accounts:
|
||||
earliest_checked = (
|
||||
db.query(func.min(Account.ck_checked_at))
|
||||
.filter(cookie_holding_filter())
|
||||
.filter(automation_account_filter(cookie_operable=False))
|
||||
.scalar()
|
||||
)
|
||||
msg = "全库暂无到期待检账号"
|
||||
|
||||
@@ -35,7 +35,6 @@ from ....models import ProxyConfig as ProxyConfigModel
|
||||
from ...account_events_service import EVENT_RELOGIN_FAILED, emit
|
||||
from ...account_lifecycle import (
|
||||
MANUAL_KINDS,
|
||||
MANUAL_STATES,
|
||||
WORK_LOGIN_RELOGIN,
|
||||
on_login_success,
|
||||
sync_status,
|
||||
@@ -44,6 +43,7 @@ from ...account_protection_service import (
|
||||
ProtectionSnapshot,
|
||||
load_protection_snapshot,
|
||||
)
|
||||
from ...account_query_filters import automation_account_filter
|
||||
from ...account_value import value_tier_expr
|
||||
from ...account_work_queue import (
|
||||
claim_account_work,
|
||||
@@ -51,7 +51,6 @@ from ...account_work_queue import (
|
||||
fail_account_work_type,
|
||||
reschedule_account_work_type,
|
||||
)
|
||||
from ...douyu_service import cookie_holding_filter, cookie_operable_filter
|
||||
from ...login_failure import classify_failure
|
||||
from ...login_service import LoginBatchRunner, get_relogin_limits
|
||||
|
||||
@@ -121,10 +120,8 @@ def build_select_query(
|
||||
query = (
|
||||
db.query(Account)
|
||||
.filter(Account.ck_check_status == "invalid")
|
||||
.filter(cookie_operable_filter())
|
||||
.filter(Account.auto_managed.is_(True))
|
||||
.filter(automation_account_filter())
|
||||
# 停用/归档的账号一律不碰(生命周期状态机,见 account_lifecycle)。
|
||||
.filter(Account.status.notin_(MANUAL_STATES))
|
||||
.filter(Account.relogin_attempts < max_attempts)
|
||||
.filter(
|
||||
or_(
|
||||
@@ -248,10 +245,8 @@ def count_pending_relogin(db: Session, *, max_attempts: int = 2) -> int:
|
||||
query = (
|
||||
db.query(func.count(Account.id))
|
||||
.filter(Account.ck_check_status == "invalid")
|
||||
.filter(cookie_holding_filter())
|
||||
.filter(Account.auto_managed.is_(True))
|
||||
.filter(automation_account_filter(cookie_operable=False))
|
||||
# 停用/归档不计入积压(它们不会被自动处理,显示出来只会误导)
|
||||
.filter(Account.status.notin_(MANUAL_STATES))
|
||||
.filter(Account.relogin_attempts < max_attempts)
|
||||
.filter(
|
||||
func.coalesce(Account.relogin_failure_kind, "").notin_(
|
||||
|
||||
@@ -52,16 +52,21 @@ from ....models import AutomationJob
|
||||
|
||||
JOB_KEY = "douyu_tasks_retention"
|
||||
|
||||
#: 只读、看一眼就走,且前端**不**拿它派生账号状态 → 短保留。
|
||||
#: 体量最大的就在这一类(`query_limited_goods` / `query_change_bind_time`)。
|
||||
NOISE_TASK_TYPES: tuple[str, ...] = (
|
||||
#: 已淘汰但仍可能有历史行的任务类型。保留在清理名单中,
|
||||
#: 避免下线入口后旧日志永久占用空间。
|
||||
RETIRED_NOISE_TASK_TYPES: tuple[str, ...] = (
|
||||
"query_limited_goods",
|
||||
"refresh_goods",
|
||||
)
|
||||
|
||||
#: 只读、看一眼就走,且前端**不**拿它派生账号状态 → 短保留。
|
||||
NOISE_TASK_TYPES: tuple[str, ...] = (
|
||||
*RETIRED_NOISE_TASK_TYPES,
|
||||
"query_change_bind_time",
|
||||
"query_gold_balance",
|
||||
"query_xpd_balance",
|
||||
"query_xpd_fragments",
|
||||
"query_points",
|
||||
"refresh_goods",
|
||||
"refresh_esports_goods",
|
||||
"refresh_xpd_goods",
|
||||
"prefetch_csrf_token",
|
||||
|
||||
Reference in New Issue
Block a user