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(), )