feat(automation): 增加登录预算动态建议
This commit is contained in:
+15
-2
@@ -11,7 +11,7 @@
|
||||
|
||||
更新时间:2026-11-21
|
||||
|
||||
整体完成度约 **82%**。
|
||||
整体完成度约 **84%**。
|
||||
|
||||
| 阶段 | 完成度 | 已落地 | 主要缺口 |
|
||||
| --- | ---: | --- | --- |
|
||||
@@ -19,7 +19,7 @@
|
||||
| 阶段 1:同步基础 | 95% | 新表、迁移、storehome 网关、全量快照、同步运行记录、内部工作队列执行器、session/points/gold/elite/esports/role/exchange 同步状态 | 少量旁路查询仍需继续收口 |
|
||||
| 阶段 2:账号与 CK | 90% | CK 周期字段、invalid 分流、登录流水、日/小时/分类/单账号预算、login_relogin 队列真实消费与退避回队、预算配置 API | 更精细的动态预算计算 |
|
||||
| 阶段 3:商品与供给 | 100% | 全量商品能力、限时窗口、原始响应、供给库存和目标缺口、定向补货入队、供给目标配置 API 与管理 UI、默认目标、统一平台状态快照、供给看板、阈值告警、7 天查询/登录/CK 趋势 | 无 |
|
||||
| 阶段 4:安全恢复自动化 | 90% | account_sync_queue 与供给补货作业默认小批量开启,自动重登消费工作队列,硬失败率熔断,登录预算在线配置且熔断阈值实时生效,按 7 天成功率自动扩缩批次,长期低成功率告警 | 生产灰度观察与动态预算参数校准 |
|
||||
| 阶段 4:安全恢复自动化 | 95% | account_sync_queue 与供给补货作业默认小批量开启,自动重登消费工作队列,硬失败率熔断,登录预算在线配置且熔断阈值实时生效,按 7 天成功率自动扩缩批次,长期低成功率告警,登录预算建议与人工一键应用 | 生产灰度观察 |
|
||||
| 阶段 5:清理旧逻辑 | 20% | 履约补货不再直接发官网请求 | 旧资料刷新、旁路查询和旧候选兜底仍需逐步下线 |
|
||||
|
||||
## 为什么重构
|
||||
@@ -545,6 +545,18 @@ Runner 启动前必须有预算 token;没有 token 时留在工作队列。
|
||||
- 近 7 天登录样本不少于 10 且成功率低于 60%;
|
||||
- 近 7 天重登失败至少 5 次且失败数高于成功数。
|
||||
|
||||
登录预算建议按以下业务量计算,不改写配额:
|
||||
|
||||
- 有效账号按平均 `7.38` 天 CK 寿命产生自然流失;
|
||||
- 失效积压按 `3` 天恢复周期计算;
|
||||
- 未登录积压按 `7` 天接入周期计算;
|
||||
- 使用近 7 天真实登录成功率;样本不足 20 条时按 70% 保守估算;
|
||||
- 邮件配额满不计入失败;
|
||||
- 自动加入至少 30 次人工保留额度;
|
||||
- 输出每日/小时/分类、单账号和并发建议,并展示与当前值的差额。
|
||||
|
||||
只有具备 `automation:manage` 权限的操作员点击“应用建议值”时才会更新预算。
|
||||
|
||||
### 阶段 5:清理旧逻辑
|
||||
|
||||
删除或降级:
|
||||
@@ -636,3 +648,4 @@ Runner 启动前必须有预算 token;没有 token 时留在工作队列。
|
||||
| 2026-11-21 | 增加供给目标管理 UI,支持新增、编辑、启停和调整安全库存 |
|
||||
| 2026-11-21 | 完成阶段 3:增加 7 天查询、登录和 CK 生命周期趋势,并补充同步时间索引 |
|
||||
| 2026-11-21 | 阶段 4:自动重登按 7 天成功率灰度扩缩批次,并增加长期低成功率告警 |
|
||||
| 2026-11-21 | 阶段 4:增加基于库存、积压和近期成功率的登录预算建议及人工一键应用 |
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
"""Login budget recommendation tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from web.backend.models import Account, LoginAttempt, LoginQuotaSetting
|
||||
from web.backend.services.login_budget_recommendation import recommend_login_budget
|
||||
|
||||
|
||||
def _account(
|
||||
name: str,
|
||||
*,
|
||||
points: int = 0,
|
||||
cookie: str = "acf_uid=1",
|
||||
ck_check_status: str = "valid",
|
||||
status: str = "active",
|
||||
) -> Account:
|
||||
return Account(
|
||||
username=name,
|
||||
password="p",
|
||||
email=f"{name}@example.com",
|
||||
email_password="ep",
|
||||
cookie=cookie,
|
||||
ck_check_status=ck_check_status,
|
||||
status=status,
|
||||
auto_managed=True,
|
||||
points=points,
|
||||
)
|
||||
|
||||
|
||||
def test_budget_recommendation_uses_inventory_and_recent_success(db):
|
||||
now = datetime.now(UTC)
|
||||
high_valid = _account("budget-high-valid", points=400)
|
||||
ordinary_valid = _account("budget-ordinary-valid")
|
||||
high_invalid = _account(
|
||||
"budget-high-invalid",
|
||||
points=400,
|
||||
ck_check_status="invalid",
|
||||
status="invalid",
|
||||
)
|
||||
ordinary_invalid = _account(
|
||||
"budget-ordinary-invalid",
|
||||
ck_check_status="invalid",
|
||||
status="invalid",
|
||||
)
|
||||
imported = _account(
|
||||
"budget-imported",
|
||||
cookie="",
|
||||
ck_check_status="",
|
||||
status="imported",
|
||||
)
|
||||
db.add_all([high_valid, ordinary_valid, high_invalid, ordinary_invalid, imported])
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
LoginAttempt(
|
||||
account_id=high_invalid.id,
|
||||
category="relogin_high_value",
|
||||
trigger_source="automation",
|
||||
started_at=now,
|
||||
finished_at=now,
|
||||
status="success" if index < 18 else "failed",
|
||||
failure_kind="" if index < 18 else "network",
|
||||
quota_day=now.date(),
|
||||
)
|
||||
for index in range(20)
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
recommendation = recommend_login_budget(db, now=now)
|
||||
|
||||
assert recommendation["basis"]["valid_accounts"] == 2
|
||||
assert recommendation["basis"]["valid_high_value"] == 1
|
||||
assert recommendation["basis"]["invalid_backlog"] == 2
|
||||
assert recommendation["basis"]["invalid_high_value"] == 1
|
||||
assert recommendation["basis"]["imported_backlog"] == 1
|
||||
assert recommendation["basis"]["recent_sample"] == 20
|
||||
assert recommendation["basis"]["recent_success_rate"] == 90.0
|
||||
assert recommendation["recommended"]["daily_attempt_limit"] >= 50
|
||||
assert recommendation["recommended"]["login_concurrency"] >= 3
|
||||
assert db.query(LoginQuotaSetting).count() == 0
|
||||
|
||||
|
||||
def test_email_quota_failures_do_not_lower_success_rate(db):
|
||||
now = datetime.now(UTC)
|
||||
account = _account("budget-email-quota", ck_check_status="invalid")
|
||||
db.add(account)
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
LoginAttempt(
|
||||
account_id=account.id,
|
||||
category="relogin_ordinary",
|
||||
trigger_source="automation",
|
||||
started_at=now,
|
||||
finished_at=now,
|
||||
status="success",
|
||||
quota_day=now.date(),
|
||||
)
|
||||
for _ in range(10)
|
||||
]
|
||||
+ [
|
||||
LoginAttempt(
|
||||
account_id=account.id,
|
||||
category="relogin_ordinary",
|
||||
trigger_source="automation",
|
||||
started_at=now,
|
||||
finished_at=now,
|
||||
status="failed",
|
||||
failure_kind="email_quota",
|
||||
quota_day=now.date(),
|
||||
)
|
||||
for _ in range(10)
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
recommendation = recommend_login_budget(db, now=now)
|
||||
|
||||
assert recommendation["basis"]["recent_sample"] == 10
|
||||
assert recommendation["basis"]["recent_success_rate"] == 100.0
|
||||
@@ -32,6 +32,7 @@ from ..services.automation import (
|
||||
run_job_now,
|
||||
scheduler_status,
|
||||
)
|
||||
from ..services.login_budget_recommendation import recommend_login_budget
|
||||
|
||||
router = APIRouter(prefix="/api/automation", tags=["自动化"])
|
||||
|
||||
@@ -179,6 +180,15 @@ def get_login_quota(
|
||||
return _login_quota_out(row)
|
||||
|
||||
|
||||
@router.get("/login-quota/recommendation")
|
||||
def get_login_quota_recommendation(
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("automation:view")),
|
||||
):
|
||||
"""Advisory budget sizing; applying it remains an explicit operator action."""
|
||||
return recommend_login_budget(db)
|
||||
|
||||
|
||||
@router.put("/login-quota")
|
||||
def update_login_quota(
|
||||
payload: LoginQuotaUpdate,
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
"""Advisory login-budget sizing from current inventory and recent outcomes."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..models import Account, LoginAttempt, LoginQuotaSetting
|
||||
from .account_lifecycle import MANUAL_KINDS, MANUAL_STATES
|
||||
from .account_value import is_high_value_expr
|
||||
|
||||
CK_AVERAGE_LIFETIME_DAYS = 7.38
|
||||
RELOGIN_RECOVERY_DAYS = 3
|
||||
ONBOARDING_RAMP_DAYS = 7
|
||||
RECENT_WINDOW_DAYS = 7
|
||||
MIN_RECENT_SAMPLE = 20
|
||||
DEFAULT_SUCCESS_RATE = 70.0
|
||||
MIN_EFFECTIVE_SUCCESS_RATE = 35.0
|
||||
MIN_DAILY_ATTEMPTS = 50
|
||||
MAX_DAILY_ATTEMPTS = 5000
|
||||
ASSUMED_ACTIVE_HOURS = 12
|
||||
|
||||
|
||||
def _automatable_accounts(db: Session):
|
||||
return db.query(Account).filter(
|
||||
Account.auto_managed.is_(True),
|
||||
Account.status.notin_(MANUAL_STATES),
|
||||
)
|
||||
|
||||
|
||||
def _count_high_value(db: Session, query) -> int:
|
||||
return int(query.filter(is_high_value_expr()).count() or 0)
|
||||
|
||||
|
||||
def _recent_login_outcomes(
|
||||
db: Session,
|
||||
*,
|
||||
now: datetime,
|
||||
) -> tuple[int, float]:
|
||||
start_day = now.date() - timedelta(days=RECENT_WINDOW_DAYS - 1)
|
||||
rows = (
|
||||
db.query(
|
||||
LoginAttempt.status,
|
||||
LoginAttempt.failure_kind,
|
||||
func.count(LoginAttempt.id),
|
||||
)
|
||||
.filter(
|
||||
LoginAttempt.quota_day >= start_day,
|
||||
LoginAttempt.category.in_(
|
||||
("onboarding", "relogin_high_value", "relogin_ordinary")
|
||||
),
|
||||
)
|
||||
.group_by(LoginAttempt.status, LoginAttempt.failure_kind)
|
||||
.all()
|
||||
)
|
||||
success = 0
|
||||
failed = 0
|
||||
for status, failure_kind, count in rows:
|
||||
count_value = int(count or 0)
|
||||
if status == "success":
|
||||
success += count_value
|
||||
elif status in {"failed", "error", "stopped"} and failure_kind != "email_quota":
|
||||
failed += count_value
|
||||
sample = success + failed
|
||||
rate = success * 100 / sample if sample else DEFAULT_SUCCESS_RATE
|
||||
return sample, round(rate, 1)
|
||||
|
||||
|
||||
def _current_quota(db: Session) -> dict[str, int]:
|
||||
row = db.query(LoginQuotaSetting).filter(LoginQuotaSetting.id == 1).first()
|
||||
if row is None:
|
||||
return {
|
||||
"daily_attempt_limit": 1500,
|
||||
"hourly_attempt_limit": 100,
|
||||
"per_account_daily_limit": 2,
|
||||
"onboarding_daily_limit": 150,
|
||||
"relogin_high_value_daily_limit": 300,
|
||||
"relogin_ordinary_daily_limit": 500,
|
||||
"manual_daily_limit": 300,
|
||||
"login_concurrency": 3,
|
||||
"failure_pause_ratio": 40,
|
||||
"enabled": True,
|
||||
}
|
||||
return {
|
||||
"daily_attempt_limit": int(row.daily_attempt_limit),
|
||||
"hourly_attempt_limit": int(row.hourly_attempt_limit),
|
||||
"per_account_daily_limit": int(row.per_account_daily_limit),
|
||||
"onboarding_daily_limit": int(row.onboarding_daily_limit),
|
||||
"relogin_high_value_daily_limit": int(
|
||||
row.relogin_high_value_daily_limit
|
||||
),
|
||||
"relogin_ordinary_daily_limit": int(row.relogin_ordinary_daily_limit),
|
||||
"manual_daily_limit": int(row.manual_daily_limit),
|
||||
"login_concurrency": int(row.login_concurrency),
|
||||
"failure_pause_ratio": int(row.failure_pause_ratio),
|
||||
"enabled": bool(row.enabled),
|
||||
}
|
||||
|
||||
|
||||
def recommend_login_budget(
|
||||
db: Session,
|
||||
*,
|
||||
now: datetime | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Return a conservative quota recommendation; never mutate current settings."""
|
||||
moment = now or datetime.now(UTC)
|
||||
manual_kinds = tuple(sorted(MANUAL_KINDS))
|
||||
|
||||
valid_query = _automatable_accounts(db).filter(
|
||||
Account.cookie.isnot(None),
|
||||
Account.cookie != "",
|
||||
Account.ck_check_status == "valid",
|
||||
)
|
||||
valid_total = int(valid_query.count() or 0)
|
||||
valid_high = _count_high_value(db, valid_query)
|
||||
valid_ordinary = max(0, valid_total - valid_high)
|
||||
|
||||
invalid_query = _automatable_accounts(db).filter(
|
||||
Account.cookie.isnot(None),
|
||||
Account.cookie != "",
|
||||
Account.ck_check_status == "invalid",
|
||||
Account.relogin_attempts < 2,
|
||||
func.coalesce(Account.relogin_failure_kind, "").notin_(manual_kinds),
|
||||
)
|
||||
invalid_total = int(invalid_query.count() or 0)
|
||||
invalid_high = _count_high_value(db, invalid_query)
|
||||
invalid_ordinary = max(0, invalid_total - invalid_high)
|
||||
imported_total = int(
|
||||
_automatable_accounts(db).filter(Account.status == "imported").count() or 0
|
||||
)
|
||||
|
||||
sample, recent_success_rate = _recent_login_outcomes(db, now=moment)
|
||||
effective_rate = (
|
||||
recent_success_rate
|
||||
if sample >= MIN_RECENT_SAMPLE
|
||||
else DEFAULT_SUCCESS_RATE
|
||||
)
|
||||
effective_rate = max(effective_rate, MIN_EFFECTIVE_SUCCESS_RATE) / 100
|
||||
|
||||
expected_daily_invalid = valid_total / CK_AVERAGE_LIFETIME_DAYS
|
||||
recovery_pressure = invalid_total / RELOGIN_RECOVERY_DAYS
|
||||
onboarding_pressure = imported_total / ONBOARDING_RAMP_DAYS
|
||||
required_success = math.ceil(
|
||||
expected_daily_invalid + recovery_pressure + onboarding_pressure
|
||||
)
|
||||
core_attempts = math.ceil(required_success / effective_rate)
|
||||
manual_reserve = max(30, math.ceil(core_attempts * 0.1))
|
||||
relogin_success = math.ceil(
|
||||
(
|
||||
invalid_total / RELOGIN_RECOVERY_DAYS
|
||||
+ valid_total / CK_AVERAGE_LIFETIME_DAYS
|
||||
)
|
||||
/ effective_rate
|
||||
)
|
||||
onboarding_attempts = math.ceil(onboarding_pressure / effective_rate)
|
||||
daily_attempts = max(
|
||||
MIN_DAILY_ATTEMPTS,
|
||||
core_attempts + manual_reserve,
|
||||
relogin_success + onboarding_attempts + manual_reserve,
|
||||
)
|
||||
daily_attempts = min(daily_attempts, MAX_DAILY_ATTEMPTS)
|
||||
hourly_attempts = max(1, math.ceil(daily_attempts / ASSUMED_ACTIVE_HOURS))
|
||||
|
||||
relogin_pressure_high = (
|
||||
valid_high / CK_AVERAGE_LIFETIME_DAYS
|
||||
+ invalid_high / RELOGIN_RECOVERY_DAYS
|
||||
)
|
||||
relogin_pressure_total = (
|
||||
valid_total / CK_AVERAGE_LIFETIME_DAYS
|
||||
+ invalid_total / RELOGIN_RECOVERY_DAYS
|
||||
)
|
||||
high_share = (
|
||||
relogin_pressure_high / relogin_pressure_total
|
||||
if relogin_pressure_total > 0
|
||||
else 0.5
|
||||
)
|
||||
relogin_high_limit = max(
|
||||
0,
|
||||
math.ceil(relogin_success * high_share),
|
||||
)
|
||||
relogin_ordinary_limit = max(0, relogin_success - relogin_high_limit)
|
||||
|
||||
if sample < MIN_RECENT_SAMPLE or recent_success_rate < 70:
|
||||
concurrency = 3
|
||||
elif recent_success_rate >= 90 and invalid_total >= 50:
|
||||
concurrency = 6
|
||||
else:
|
||||
concurrency = 4
|
||||
|
||||
recommended = {
|
||||
"daily_attempt_limit": daily_attempts,
|
||||
"hourly_attempt_limit": hourly_attempts,
|
||||
"per_account_daily_limit": 2,
|
||||
"onboarding_daily_limit": onboarding_attempts,
|
||||
"relogin_high_value_daily_limit": relogin_high_limit,
|
||||
"relogin_ordinary_daily_limit": relogin_ordinary_limit,
|
||||
"manual_daily_limit": manual_reserve,
|
||||
"login_concurrency": concurrency,
|
||||
}
|
||||
current = _current_quota(db)
|
||||
return {
|
||||
"generated_at": moment,
|
||||
"window_days": RECENT_WINDOW_DAYS,
|
||||
"basis": {
|
||||
"valid_accounts": valid_total,
|
||||
"valid_high_value": valid_high,
|
||||
"valid_ordinary": valid_ordinary,
|
||||
"invalid_backlog": invalid_total,
|
||||
"invalid_high_value": invalid_high,
|
||||
"invalid_ordinary": invalid_ordinary,
|
||||
"imported_backlog": imported_total,
|
||||
"recent_sample": sample,
|
||||
"recent_success_rate": recent_success_rate,
|
||||
"effective_success_rate": round(effective_rate * 100, 1),
|
||||
"expected_daily_invalid": round(expected_daily_invalid, 2),
|
||||
"required_daily_success": required_success,
|
||||
"manual_reserve": manual_reserve,
|
||||
},
|
||||
"current": current,
|
||||
"recommended": recommended,
|
||||
"delta": {
|
||||
key: recommended[key] - current[key]
|
||||
for key in recommended
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
__all__ = ["recommend_login_budget"]
|
||||
@@ -1,6 +1,8 @@
|
||||
import api from "./client";
|
||||
import type {
|
||||
AutomationJobItem,
|
||||
AutomationLoginQuota,
|
||||
AutomationLoginQuotaRecommendation,
|
||||
AutomationManualQueue,
|
||||
AutomationJobUpdate,
|
||||
AutomationJobsResponse,
|
||||
@@ -11,6 +13,17 @@ import type {
|
||||
export const automationApi = {
|
||||
jobs: () =>
|
||||
api.get<AutomationJobsResponse, AutomationJobsResponse>("/automation/jobs"),
|
||||
loginQuota: () =>
|
||||
api.get<AutomationLoginQuota, AutomationLoginQuota>("/automation/login-quota"),
|
||||
loginQuotaRecommendation: () =>
|
||||
api.get<AutomationLoginQuotaRecommendation, AutomationLoginQuotaRecommendation>(
|
||||
"/automation/login-quota/recommendation",
|
||||
),
|
||||
updateLoginQuota: (payload: AutomationLoginQuota) =>
|
||||
api.put<AutomationLoginQuota, AutomationLoginQuota>(
|
||||
"/automation/login-quota",
|
||||
payload,
|
||||
),
|
||||
updateJob: (key: string, payload: AutomationJobUpdate) =>
|
||||
api.patch<AutomationJobItem, AutomationJobItem>(
|
||||
`/automation/jobs/${key}`,
|
||||
|
||||
@@ -1658,6 +1658,43 @@ export interface AutomationJobUpdate {
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
export interface AutomationLoginQuota {
|
||||
daily_attempt_limit: number;
|
||||
hourly_attempt_limit: number;
|
||||
per_account_daily_limit: number;
|
||||
onboarding_daily_limit: number;
|
||||
relogin_high_value_daily_limit: number;
|
||||
relogin_ordinary_daily_limit: number;
|
||||
manual_daily_limit: number;
|
||||
login_concurrency: number;
|
||||
failure_pause_ratio: number;
|
||||
enabled: boolean;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface AutomationLoginQuotaRecommendation {
|
||||
generated_at: string;
|
||||
window_days: number;
|
||||
basis: {
|
||||
valid_accounts: number;
|
||||
valid_high_value: number;
|
||||
valid_ordinary: number;
|
||||
invalid_backlog: number;
|
||||
invalid_high_value: number;
|
||||
invalid_ordinary: number;
|
||||
imported_backlog: number;
|
||||
recent_sample: number;
|
||||
recent_success_rate: number;
|
||||
effective_success_rate: number;
|
||||
expected_daily_invalid: number;
|
||||
required_daily_success: number;
|
||||
manual_reserve: number;
|
||||
};
|
||||
current: AutomationLoginQuota;
|
||||
recommended: Omit<AutomationLoginQuota, "failure_pause_ratio" | "enabled" | "updated_at">;
|
||||
delta: Record<string, number>;
|
||||
}
|
||||
|
||||
export interface AutomationRunOutcome {
|
||||
job_key: string;
|
||||
status: string;
|
||||
|
||||
@@ -15,12 +15,17 @@ import {
|
||||
Typography,
|
||||
} from "antd";
|
||||
import type { ColumnsType } from "antd/es/table";
|
||||
import { ReloadOutlined, ThunderboltOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
CheckCircleOutlined,
|
||||
ReloadOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { message } from "../utils/antdMessage";
|
||||
import { getErrorMessage } from "../utils/error";
|
||||
import {
|
||||
automationApi,
|
||||
type AutomationJobItem,
|
||||
type AutomationLoginQuotaRecommendation,
|
||||
type AutomationManualGroup,
|
||||
type AutomationManualSample,
|
||||
type AutomationRunItem,
|
||||
@@ -38,6 +43,17 @@ const STATUS_TAG: Record<string, { color: string; text: string }> = {
|
||||
skipped: { color: "default", text: "已跳过" },
|
||||
};
|
||||
|
||||
const BUDGET_LABELS: Record<string, string> = {
|
||||
daily_attempt_limit: "每日尝试",
|
||||
hourly_attempt_limit: "每小时尝试",
|
||||
per_account_daily_limit: "单账号每日",
|
||||
onboarding_daily_limit: "首次登录",
|
||||
relogin_high_value_daily_limit: "高价值重登",
|
||||
relogin_ordinary_daily_limit: "普通重登",
|
||||
manual_daily_limit: "人工保留",
|
||||
login_concurrency: "登录并发",
|
||||
};
|
||||
|
||||
function nextRunLabel(job: AutomationJobItem): ReactNode {
|
||||
if (!job.enabled) {
|
||||
return <Typography.Text type="secondary">未启用</Typography.Text>;
|
||||
@@ -70,7 +86,10 @@ export default function AutomationPage() {
|
||||
const [manualGroups, setManualGroups] = useState<AutomationManualGroup[]>([]);
|
||||
const [manualTotal, setManualTotal] = useState(0);
|
||||
const [pendingRelogin, setPendingRelogin] = useState(0);
|
||||
const [budgetRecommendation, setBudgetRecommendation] =
|
||||
useState<AutomationLoginQuotaRecommendation | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [applyingBudget, setApplyingBudget] = useState(false);
|
||||
const [savingKey, setSavingKey] = useState<string | null>(null);
|
||||
const [runningKey, setRunningKey] = useState<string | null>(null);
|
||||
const [forms] = Form.useForm();
|
||||
@@ -80,8 +99,12 @@ export default function AutomationPage() {
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await automationApi.jobs();
|
||||
const [data, recommendation] = await Promise.all([
|
||||
automationApi.jobs(),
|
||||
automationApi.loginQuotaRecommendation(),
|
||||
]);
|
||||
setJobs(data.jobs);
|
||||
setBudgetRecommendation(recommendation);
|
||||
setPendingRelogin(data.pending_relogin ?? 0);
|
||||
setSchedulerEnabled(data.scheduler.enabled);
|
||||
setSchedulerRunning(data.scheduler.running);
|
||||
@@ -161,6 +184,23 @@ export default function AutomationPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const applyBudgetRecommendation = async () => {
|
||||
if (!budgetRecommendation) return;
|
||||
setApplyingBudget(true);
|
||||
try {
|
||||
await automationApi.updateLoginQuota({
|
||||
...budgetRecommendation.current,
|
||||
...budgetRecommendation.recommended,
|
||||
});
|
||||
message.success("登录预算已按建议值更新");
|
||||
await load();
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setApplyingBudget(false);
|
||||
}
|
||||
};
|
||||
|
||||
const manualColumns: ColumnsType<AutomationManualSample> = [
|
||||
{ title: "账号ID", dataIndex: "account_id", width: 80 },
|
||||
{
|
||||
@@ -235,6 +275,24 @@ export default function AutomationPage() {
|
||||
{ title: "说明", dataIndex: "message", ellipsis: true },
|
||||
];
|
||||
|
||||
const budgetRows = budgetRecommendation
|
||||
? Object.entries(BUDGET_LABELS).map(([key, label]) => ({
|
||||
key,
|
||||
label,
|
||||
current: Number(
|
||||
budgetRecommendation.current[
|
||||
key as keyof typeof budgetRecommendation.current
|
||||
] ?? 0,
|
||||
),
|
||||
recommended: Number(
|
||||
budgetRecommendation.recommended[
|
||||
key as keyof typeof budgetRecommendation.recommended
|
||||
] ?? 0,
|
||||
),
|
||||
delta: Number(budgetRecommendation.delta[key] ?? 0),
|
||||
}))
|
||||
: [];
|
||||
|
||||
return (
|
||||
<Space direction="vertical" size="middle" style={{ width: "100%" }}>
|
||||
<Card
|
||||
@@ -398,6 +456,87 @@ export default function AutomationPage() {
|
||||
</Form>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="登录预算建议"
|
||||
extra={
|
||||
<Popconfirm
|
||||
title="应用建议预算?"
|
||||
description="会覆盖当前登录预算;失败率熔断比例和启停状态保持不变。"
|
||||
onConfirm={() => void applyBudgetRecommendation()}
|
||||
disabled={!canManage || !budgetRecommendation}
|
||||
okText="应用"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<CheckCircleOutlined />}
|
||||
disabled={!canManage || !budgetRecommendation}
|
||||
loading={applyingBudget}
|
||||
>
|
||||
应用建议值
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
}
|
||||
>
|
||||
{budgetRecommendation ? (
|
||||
<>
|
||||
<Descriptions size="small" column={3} style={{ marginBottom: 16 }}>
|
||||
<Descriptions.Item label="有效账号">
|
||||
{budgetRecommendation.basis.valid_accounts}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="失效积压">
|
||||
{budgetRecommendation.basis.invalid_backlog}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="未登录积压">
|
||||
{budgetRecommendation.basis.imported_backlog}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="近期样本">
|
||||
{budgetRecommendation.basis.recent_sample}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="近期成功率">
|
||||
{budgetRecommendation.basis.recent_success_rate.toFixed(1)}%
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="建议每日成功需求">
|
||||
{budgetRecommendation.basis.required_daily_success}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{budgetRecommendation.basis.recent_sample < 20 ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 12 }}
|
||||
message="近期样本不足 20 条,建议值暂按保守成功率 70% 计算"
|
||||
/>
|
||||
) : null}
|
||||
<Table
|
||||
rowKey="key"
|
||||
size="small"
|
||||
pagination={false}
|
||||
dataSource={budgetRows}
|
||||
columns={[
|
||||
{ title: "预算项", dataIndex: "label" },
|
||||
{ title: "当前", dataIndex: "current", width: 110 },
|
||||
{ title: "建议", dataIndex: "recommended", width: 110 },
|
||||
{
|
||||
title: "差额",
|
||||
dataIndex: "delta",
|
||||
width: 100,
|
||||
render: (value: number) => (
|
||||
<Typography.Text
|
||||
type={value > 0 ? "success" : value < 0 ? "danger" : "secondary"}
|
||||
>
|
||||
{value > 0 ? `+${value}` : value}
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Typography.Text type="secondary">暂无预算建议</Typography.Text>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="待人工处理"
|
||||
extra={
|
||||
|
||||
Reference in New Issue
Block a user