修复(履约重试): 绑定失败无账号任务允许重新选号

- prepare_manual_allocation 支持 binding_failed/lease_expired 的人工重新选号
- 客户刷新时把任务重置为 ready 并唤醒选号
- 保留客户资料,分配成功后继续启动绑定
- 补充重试测试
This commit is contained in:
yml
2026-11-25 14:04:50 +08:00
parent 18df3443d8
commit eab1d1937a
3 changed files with 67 additions and 0 deletions
+27
View File
@@ -1332,6 +1332,33 @@ class TestAccountSelection(_Base):
assert task.next_allocate_at is not None assert task.next_allocate_at is not None
assert old_retry_at is None or task.next_allocate_at >= old_retry_at assert old_retry_at is None or task.next_allocate_at >= old_retry_at
def test_manual_allocation_allows_rebind_after_released_binding_failure(self):
task = self.task()
task.execution_status = "manual_required"
task.binding_status = "failed"
task.issue_code = "binding_failed"
task.last_error = "绑定二维码已过期"
self.session.commit()
detail = service.prepare_manual_allocation(
self.session,
task_id=task.id,
current=self.admin,
)
self.session.refresh(task)
assert detail["task"]["executionStatus"] == "ready"
assert task.execution_status == "ready"
assert task.binding_status == "not_started"
assert task.issue_code == ""
assert task.next_allocate_at is not None
assert (
self.session.query(PlatformFulfillmentEvent)
.filter_by(task_id=task.id, event_type="binding_retry_requested")
.count()
== 1
)
def test_capability_match_uses_local_index_without_live_probe(self): def test_capability_match_uses_local_index_without_live_probe(self):
account = self.account("capability-fast", capability=False) account = self.account("capability-fast", capability=False)
task = self.task() task = self.task()
@@ -616,6 +616,34 @@ def prepare_manual_allocation(
lease = db.query(AccountLease).filter(AccountLease.id == task.lease_id).first() lease = db.query(AccountLease).filter(AccountLease.id == task.lease_id).first()
if lease and lease.status == "active": if lease and lease.status == "active":
return get_task_detail(db, task.id) return get_task_detail(db, task.id)
if (
task.execution_status == "manual_required"
and not task.account_id
and not task.lease_id
and task.issue_code in {"binding_failed", "lease_expired"}
):
# 绑定失败账号已释放后,人工触发一次重新选号;
# 客户资料保留,分配成功后 auto allocator 会继续启动绑定。
task.execution_status = "ready"
task.binding_status = "not_started"
task.bind_task_id = None
task.issue_code = ""
task.last_error = ""
task.next_allocate_at = _now()
task.operator_id = current.id
task.updated_at = _now()
task.state_version = int(task.state_version or 0) + 1
_append_event(
db,
task.id,
"binding_retry_requested",
actor_type="user",
actor_id=current.id,
detail={"reason": "manual_reallocate_after_binding_failure"},
)
_emit_order_site_binding_state(db, task.id)
db.flush()
return get_task_detail(db, task.id)
if task.execution_status != "ready": if task.execution_status != "ready":
raise HTTPException(status_code=409, detail="只有待分配任务可以重新选号") raise HTTPException(status_code=409, detail="只有待分配任务可以重新选号")
task.next_allocate_at = _now() task.next_allocate_at = _now()
@@ -131,6 +131,18 @@ async def customer_start_binding(
raise HTTPException(status_code=409, detail="请先提交游戏角色和游戏主页截图") raise HTTPException(status_code=409, detail="请先提交游戏角色和游戏主页截图")
if not task.account_id or not task.lease_id: if not task.account_id or not task.lease_id:
if (
task.execution_status == "manual_required"
and task.issue_code in {"binding_failed", "lease_expired"}
):
from .allocation import prepare_manual_allocation
prepare_manual_allocation(
db,
task_id=task.id,
current=_integration_actor(db),
)
db.commit()
from .auto_allocator import wake_auto_allocator from .auto_allocator import wake_auto_allocator
wake_auto_allocator([int(task.id)]) wake_auto_allocator([int(task.id)])