优化(履约租约): 绑定失败保留账号直到人工释放

- clean 任务 binding_failed 租约改为无限期保留
- Reaper 不再自动释放 clean 绑定失败账号,只保留历史任务旧策略
- 迁移 0133 清理存量 clean 绑定失败租约到期时间
- 工作台显示账号保留中并提供人工释放
- 补充租约/回收测试
This commit is contained in:
yml
2026-11-25 13:47:34 +08:00
parent adf2e9a066
commit 18df3443d8
7 changed files with 105 additions and 13 deletions
@@ -13,6 +13,7 @@ from ...platform_fulfillment.account_selector import (
expire_platform_fulfillment_leases,
release_lease,
)
from ...platform_fulfillment.common import FLOW_VERSION_CLEAN
from ...platform_fulfillment.service import binding_failed_lease_ttl_minutes
JOB_KEY = "platform_fulfillment_lease_reaper"
@@ -41,6 +42,8 @@ def run_platform_fulfillment_lease_reaper(
AccountLease.expires_at.is_(None),
PlatformFulfillmentTask.execution_status == "manual_required",
PlatformFulfillmentTask.issue_code == "binding_failed",
# 新流程绑定失败账号保留到人工释放;只清理历史存量。
PlatformFulfillmentTask.flow_version != FLOW_VERSION_CLEAN,
PlatformFulfillmentTask.updated_at <= stale_binding_cutoff,
Account.role_bind_status == "unbound",
)
@@ -67,6 +70,31 @@ def run_platform_fulfillment_lease_reaper(
.limit(max(1, int(job.batch_size or 500)))
.all()
)
held_leases: list[AccountLease] = []
if candidate_leases:
held_tasks = (
db.query(PlatformFulfillmentTask)
.filter(
PlatformFulfillmentTask.lease_id.in_(
[int(lease.id) for lease in candidate_leases]
),
PlatformFulfillmentTask.flow_version == FLOW_VERSION_CLEAN,
PlatformFulfillmentTask.execution_status == "manual_required",
PlatformFulfillmentTask.issue_code == "binding_failed",
)
.all()
)
held_lease_ids = {int(task.lease_id) for task in held_tasks if task.lease_id}
held_leases = [
lease for lease in candidate_leases if int(lease.id) in held_lease_ids
]
candidate_leases = [
lease for lease in candidate_leases if int(lease.id) not in held_lease_ids
]
for lease in held_leases:
lease.expires_at = None
if held_leases:
db.flush()
released_ids = {int(lease.id) for lease in candidate_leases}
converted_tasks: dict[int, PlatformFulfillmentTask] = {}
if candidate_leases: