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
+53
View File
@@ -6,6 +6,7 @@ from datetime import UTC, datetime, timedelta
from web.backend.models import (
Account,
AccountLease,
AutomationJob,
DouyuExternalOrder,
PlatformFulfillmentTask,
@@ -123,6 +124,58 @@ def test_protection_membership_uses_active_fulfillment_relationships(db):
)
def test_lease_bound_includes_all_active_lease_purposes(db):
user = User(
username="lease-protection-user",
password_hash="h",
role="super_admin",
is_active=True,
)
leased = _account("protection-leased")
collab_leased = _account("protection-collab-leased")
released = _account("protection-released")
other_purpose = _account("protection-other-purpose")
db.add_all([user, leased, collab_leased, released, other_purpose])
db.flush()
db.add_all(
[
AccountLease(
account_id=leased.id,
holder_user_id=user.id,
purpose="platform_fulfillment",
status="active",
),
AccountLease(
account_id=collab_leased.id,
holder_user_id=user.id,
purpose="douyu_collab",
status="active",
),
AccountLease(
account_id=released.id,
holder_user_id=user.id,
purpose="platform_fulfillment",
status="released",
),
AccountLease(
account_id=other_purpose.id,
holder_user_id=user.id,
purpose="other",
status="active",
),
]
)
db.commit()
snapshot = load_protection_snapshot(db, job_config=None)
assert snapshot.group_account_ids["lease_bound"] == frozenset(
{leased.id, collab_leased.id}
)
assert snapshot.groups["lease_bound"]["probe_interval_minutes"] == 30
assert leased.id in snapshot.relogin_ids
def test_protection_target_reports_ck_health_and_shortage(db):
valid = _account("protection-valid")
invalid = _account("protection-invalid", ck_status="invalid")