From 1081e93522dc104cc2175e09cd72571fde966d56 Mon Sep 17 00:00:00 2001 From: yml Date: Tue, 24 Nov 2026 18:36:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(automation):=20=E7=A7=9F=E7=BA=A6=E5=B7=A1?= =?UTF-8?q?=E6=A3=80=E9=99=8D=E4=B8=BA4=E5=B0=8F=E6=97=B6=E5=B9=B6?= =?UTF-8?q?=E6=94=B6=E7=B4=A7=E9=A6=96=E6=AC=A1=E7=99=BB=E5=BD=95=E6=A0=B7?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - lease_bound 30 分钟会超出 ck_health 吞吐,改为 240 分钟 - 首次登录样本排除缺账号/密码和已判极验/凭证失败的账号 - 补充保护组和首登样本准入测试 --- docs/设计-账号全生命周期.md | 9 ++++++++- tests/test_account_onboarding_job.py | 13 +++++++++++++ tests/test_account_protection_service.py | 2 +- web/backend/services/account_protection_service.py | 2 +- .../services/automation/jobs/account_onboarding.py | 14 +++++++++++++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/docs/设计-账号全生命周期.md b/docs/设计-账号全生命周期.md index 78f52db..f4d9042 100644 --- a/docs/设计-账号全生命周期.md +++ b/docs/设计-账号全生命周期.md @@ -281,7 +281,7 @@ CK 本体和健康结果都在账号上: - 成员:`account_leases.status=active` 且 purpose 为 `platform_fulfillment` / `douyu_collab`; - 默认开启; -- 巡检间隔 30 分钟(比普通账号更短); +- 巡检间隔 240 分钟(比普通账号更短,且不挤占 ck_health 吞吐); - 自动重登开启。 这样所有生效租约账号都会进入 CK 巡检和失效重登保护,不再只覆盖预售/协作单。 @@ -308,3 +308,10 @@ CK 本体和健康结果都在账号上: 租约账号在履约期间 CK 失效会出现不可用窗口;提前登录可以把窗口前移到空闲时段。 作业不直接改绑定或订单,只刷新 Cookie。 + + +### 首次登录样本 + +`account_onboarding` 保持默认关闭。先点“立即跑一次”跑 20 个样本,不打开自动作业; +样本账号会排除缺账号/密码和已判定极验/凭证失败的账号,避免样本被必失败账号污染。 +确认成功率、失败分型和登录后商品能力同步后,再启用作业放量。 diff --git a/tests/test_account_onboarding_job.py b/tests/test_account_onboarding_job.py index 482798f..cca7d01 100644 --- a/tests/test_account_onboarding_job.py +++ b/tests/test_account_onboarding_job.py @@ -70,6 +70,19 @@ def test_selector_only_picks_unlogged_automatable_accounts(db): assert job.count_pending_onboarding(db) == 1 +def test_selector_skips_missing_password_and_manual_failure(db): + _admin(db) + selectable = _account("onboarding-eligible") + missing_password = _account("onboarding-no-password", password="") + manual_failure = _account("onboarding-captcha", relogin_failure_kind="captcha") + db.add_all([selectable, missing_password, manual_failure]) + db.commit() + + rows = job.build_select_query(db, _job()).all() + + assert [row.id for row in rows] == [selectable.id] + + def test_run_account_onboarding_returns_batch_summary(db, monkeypatch): _admin(db) first = _account("onboarding-first") diff --git a/tests/test_account_protection_service.py b/tests/test_account_protection_service.py index a0f5a3b..2c8a300 100644 --- a/tests/test_account_protection_service.py +++ b/tests/test_account_protection_service.py @@ -172,7 +172,7 @@ def test_lease_bound_includes_all_active_lease_purposes(db): assert snapshot.group_account_ids["lease_bound"] == frozenset( {leased.id, collab_leased.id} ) - assert snapshot.groups["lease_bound"]["probe_interval_minutes"] == 30 + assert snapshot.groups["lease_bound"]["probe_interval_minutes"] == 240 assert leased.id in snapshot.relogin_ids diff --git a/web/backend/services/account_protection_service.py b/web/backend/services/account_protection_service.py index b3f478b..6aa29d2 100644 --- a/web/backend/services/account_protection_service.py +++ b/web/backend/services/account_protection_service.py @@ -61,7 +61,7 @@ GROUP_DEFINITIONS: dict[str, dict[str, Any]] = { "description": "当前所有生效的直播履约/协作租约账号,优先 CK 巡检和到期前刷新", "enabled": True, "target_count": 0, - "probe_interval_minutes": 30, + "probe_interval_minutes": 240, "auto_relogin": True, }, } diff --git a/web/backend/services/automation/jobs/account_onboarding.py b/web/backend/services/automation/jobs/account_onboarding.py index de8a698..1d5c423 100644 --- a/web/backend/services/automation/jobs/account_onboarding.py +++ b/web/backend/services/automation/jobs/account_onboarding.py @@ -9,7 +9,7 @@ from sqlalchemy import func, or_, select from sqlalchemy.orm import Session from ....models import Account, AutomationJob, LoginTask -from ...account_lifecycle import MANUAL_STATES, STATUS_MANUAL +from ...account_lifecycle import MANUAL_KINDS, MANUAL_STATES, STATUS_MANUAL from ...login_automation import run_login_batch_with_fallback, system_user_id JOB_KEY = "account_onboarding" @@ -38,6 +38,13 @@ def build_select_query( .filter( Account.auto_managed.is_(True), Account.status.notin_((*MANUAL_STATES, STATUS_MANUAL)), + # 缺账号/密码的账号首登必失败,不能占样本名额。 + Account.username != "", + Account.password != "", + # 已经判定为极验/凭证问题的账号不再自动首登。 + func.coalesce(Account.relogin_failure_kind, "").notin_( + tuple(sorted(MANUAL_KINDS)) + ), or_(Account.cookie.is_(None), Account.cookie == ""), ~_in_flight_login_exists(), ) @@ -53,6 +60,11 @@ def count_pending_onboarding(db: Session) -> int: .filter( Account.auto_managed.is_(True), Account.status.notin_((*MANUAL_STATES, STATUS_MANUAL)), + Account.username != "", + Account.password != "", + func.coalesce(Account.relogin_failure_kind, "").notin_( + tuple(sorted(MANUAL_KINDS)) + ), or_(Account.cookie.is_(None), Account.cookie == ""), ~_in_flight_login_exists(), )