feat(automation): 增加租约 CK 到期前刷新

- 保护组新增 lease_bound,覆盖全部生效履约/协作租约
- 新增 lease_ck_refresh 作业,提前 24h 为有效 CK 续期
- 已失效重登仍由 ck_relogin 处理
- 失败按类型设置退避,避免每轮重复撞
- 补充保护组、选行、作业执行测试
This commit is contained in:
yml
2026-11-24 18:04:09 +08:00
parent 2e6303361c
commit 03c7c74eab
8 changed files with 442 additions and 1 deletions
@@ -22,6 +22,7 @@ from sqlalchemy.orm import Session
from ..models import (
Account,
AccountLease,
AutomationJob,
DouyuExternalOrder,
PlatformFulfillmentTask,
@@ -55,6 +56,14 @@ GROUP_DEFINITIONS: dict[str, dict[str, Any]] = {
"probe_interval_minutes": DEFAULT_PROBE_INTERVAL_MINUTES,
"auto_relogin": True,
},
"lease_bound": {
"label": "生效租约账号",
"description": "当前所有生效的直播履约/协作租约账号,优先 CK 巡检和到期前刷新",
"enabled": True,
"target_count": 0,
"probe_interval_minutes": 30,
"auto_relogin": True,
},
}
@@ -136,6 +145,19 @@ def _collab_account_ids(db: Session) -> set[int]:
return {int(row[0]) for row in rows if row[0] is not None}
def _lease_account_ids(db: Session) -> set[int]:
rows = (
db.query(AccountLease.account_id)
.filter(
AccountLease.status == "active",
AccountLease.purpose.in_(("platform_fulfillment", "douyu_collab")),
)
.distinct()
.all()
)
return {int(row[0]) for row in rows if row[0] is not None}
@dataclass(frozen=True)
class ProtectionSnapshot:
groups: dict[str, dict[str, Any]]
@@ -189,6 +211,7 @@ def load_protection_snapshot(
group_account_ids={
"presale_bound": frozenset(_presale_account_ids(db)),
"collab_bound": frozenset(_collab_account_ids(db)),
"lease_bound": frozenset(_lease_account_ids(db)),
},
)