Files
live-hub-py/web/backend/services/automation/jobs/account_supply_profile_projection.py
T
yml f15ae99012 feat(accounts): 增加账号供给画像投影
- 新增 account_supply_profiles 表与迁移
- 按租约/生命周期/价值/能力计算角色、质量分、冗余
- 新增 account_supply_profile_projection 作业,默认开启
- 账号列表展示供给画像列
- 补充画像角色/评分/游标/作业测试
2026-11-24 16:16:18 +08:00

52 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""账号供给画像投影刷新。"""
from __future__ import annotations
from datetime import UTC, datetime
from typing import Any
from sqlalchemy.orm import Session
from ....models import AutomationJob
from ...account_supply_profile_service import refresh_account_supply_profiles
JOB_KEY = "account_supply_profile_projection"
def run_account_supply_profile_projection(
db: Session,
job: AutomationJob,
) -> dict[str, Any]:
config = dict(job.config or {})
cursor = int(config.get("last_account_id") or 0)
result = refresh_account_supply_profiles(
db,
limit=max(1, int(job.batch_size or 5000)),
after_account_id=cursor,
)
if result["hasMore"]:
config["last_account_id"] = int(result["nextId"])
else:
config["last_account_id"] = 0
job.config = config
job.updated_at = datetime.now(UTC)
db.commit()
return {
"scanned": result["processed"],
"valid": 0,
"invalid": 0,
"skipped": 0,
"message": (
f"刷新账号供给画像 {result['processed']} 条,"
f"游标 {result['nextId']},{'继续下一批' if result['hasMore'] else '本轮已到末尾'}"
),
"detail": {
"processed": result["processed"],
"nextId": result["nextId"],
"hasMore": result["hasMore"],
},
}
__all__ = ["JOB_KEY", "run_account_supply_profile_projection"]