优化(账号自动化): 受保护账号极验重登允许按上限重试

This commit is contained in:
yml
2026-11-26 09:52:22 +08:00
parent 5a1552915e
commit 8eadb875fe
4 changed files with 163 additions and 10 deletions
+27 -1
View File
@@ -20,7 +20,7 @@ from .account_capability_service import (
OFFER_STATE_ACTIVE,
OFFER_STATE_BEFORE,
)
from .account_lifecycle import MANUAL_STATES
from .account_lifecycle import MANUAL_KINDS, MANUAL_STATES
ACTIVE_COLLAB_STATUSES: tuple[str, ...] = (
"incomplete",
@@ -94,6 +94,31 @@ def automation_account_filter(*, cookie_operable: bool = True):
)
def relogin_failure_kind_filter(
*,
protected_ids: set[int] | frozenset[int],
max_attempts: int,
):
"""自动重登的失败分型准入。
普通账号的极验失败仍直接转人工;履约保护账号允许多试到账户次数上限,
因为它们持有生效租约/进行中订单,不能因为一次滑块失败就饿死。
"""
kind = func.coalesce(Account.relogin_failure_kind, "")
base = kind.notin_(tuple(sorted(MANUAL_KINDS)))
ids = sorted({int(value) for value in protected_ids})
if not ids:
return base
return or_(
base,
and_(
Account.id.in_(ids),
kind == "captcha",
Account.relogin_attempts < max(1, int(max_attempts)),
),
)
def assigned_to_pool_filter():
return or_(
Account.assigned_to.is_(None),
@@ -190,6 +215,7 @@ __all__ = [
"fresh_eligible_state_filter",
"pool_owner_ids",
"recent_elite_bind_lock_exists",
"relogin_failure_kind_filter",
"role_change_ready_filter",
"valid_ck_filter",
]
@@ -44,7 +44,10 @@ from ...account_protection_service import (
ProtectionSnapshot,
load_protection_snapshot,
)
from ...account_query_filters import automation_account_filter
from ...account_query_filters import (
automation_account_filter,
relogin_failure_kind_filter,
)
from ...account_value import is_high_value_expr, value_tier_expr
from ...account_work_queue import (
WORK_AGING_SECONDS,
@@ -179,8 +182,9 @@ def _eligible_account_query(
.filter(Account.relogin_attempts < max_attempts)
# 已判定需要人工的类型不再自动重试。空值用 coalesce 兜住历史值。
.filter(
func.coalesce(Account.relogin_failure_kind, "").notin_(
tuple(sorted(MANUAL_KINDS))
relogin_failure_kind_filter(
protected_ids=protection.relogin_ids,
max_attempts=max_attempts,
)
)
)
@@ -961,6 +965,7 @@ def settle_results(
"email_quota": 0,
"skipped": 0,
}
protected_ids = load_protection_snapshot(db).relogin_ids
for account_id in account_ids:
entry = fresh.get(account_id)
if entry is None:
@@ -1007,7 +1012,14 @@ def settle_results(
account.relogin_failure_kind = kind
account.relogin_last_error = (task.attempt_message or "")[:500]
account.relogin_attempts = int(account.relogin_attempts or 0) + 1
if kind in MANUAL_KINDS or account.relogin_attempts >= max_attempts:
protected_captcha_retry = (
kind == "captcha"
and int(account.id) in protected_ids
and account.relogin_attempts < max_attempts
)
if (
kind in MANUAL_KINDS and not protected_captcha_retry
) or account.relogin_attempts >= max_attempts:
# 转人工:极验/凭证问题重试无意义,次数用尽也不该无限撞。
counters["manual"] += 1
account.relogin_next_at = None
+20 -5
View File
@@ -18,7 +18,10 @@ from ..models import (
)
from .account_lifecycle import DEFAULT_CK_LIFETIME, MANUAL_KINDS
from .account_protection_service import ProtectionSnapshot, load_protection_snapshot
from .account_query_filters import automation_account_filter
from .account_query_filters import (
automation_account_filter,
relogin_failure_kind_filter,
)
from .account_value import is_high_value_account, is_high_value_expr
from .douyu_service import LOGIN_ATTEMPT_IN_FLIGHT_STATUSES
@@ -256,6 +259,7 @@ def _pending_protected_invalid_query(
*,
protection: ProtectionSnapshot,
now: datetime,
max_attempts: int = 2,
):
relogin_ids = protection.relogin_ids
if not relogin_ids:
@@ -264,8 +268,9 @@ def _pending_protected_invalid_query(
Account.id.in_(relogin_ids),
Account.ck_check_status == "invalid",
automation_account_filter(cookie_operable=True),
func.coalesce(Account.relogin_failure_kind, "").notin_(
tuple(sorted(MANUAL_KINDS))
relogin_failure_kind_filter(
protected_ids=relogin_ids,
max_attempts=max_attempts,
),
or_(
Account.relogin_next_at.is_(None),
@@ -377,7 +382,12 @@ def _tier_reserve_needed(
)
p0_pending = _count_available_today(
_pending_protected_invalid_query(db, protection=protection, now=now),
_pending_protected_invalid_query(
db,
protection=protection,
now=now,
max_attempts=per_account_limit,
),
per_account_limit=per_account_limit,
quota_day=quota_day,
)
@@ -424,7 +434,12 @@ def get_login_quota_usage_summary(
per_account_limit = int(setting.per_account_daily_limit)
p0_pending = _count_available_today(
_pending_protected_invalid_query(db, protection=protection, now=moment),
_pending_protected_invalid_query(
db,
protection=protection,
now=moment,
max_attempts=per_account_limit,
),
per_account_limit=per_account_limit,
quota_day=quota_day,
)