优化(履约租约): 绑定失败保留账号直到人工释放
- clean 任务 binding_failed 租约改为无限期保留 - Reaper 不再自动释放 clean 绑定失败账号,只保留历史任务旧策略 - 迁移 0133 清理存量 clean 绑定失败租约到期时间 - 工作台显示账号保留中并提供人工释放 - 补充租约/回收测试
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -28,6 +28,7 @@ from .binding_status import (
|
||||
)
|
||||
from .common import (
|
||||
BINDING_COOLDOWN_ISSUES,
|
||||
FLOW_VERSION_CLEAN,
|
||||
_jsonable,
|
||||
_now,
|
||||
binding_failed_lease_ttl_minutes,
|
||||
@@ -92,6 +93,9 @@ def _lease_policy_for_task(
|
||||
return "cancelled", 0
|
||||
if status == "manual_required":
|
||||
if task.issue_code == "binding_failed":
|
||||
# Clean 任务绑定失败时保留账号,直到绑定成功或人工释放。
|
||||
if task.flow_version == FLOW_VERSION_CLEAN:
|
||||
return "binding_failed_hold", None
|
||||
return (
|
||||
"binding_failed_cleanup",
|
||||
binding_failed_lease_ttl_minutes(),
|
||||
|
||||
Reference in New Issue
Block a user