fix(platform-fulfillment): 释放空闲连接并合并选号请求
This commit is contained in:
@@ -2045,6 +2045,34 @@ def upsert_mapping(
|
||||
return update_mapping(db, mapping_id=row.id, **values)
|
||||
|
||||
|
||||
def prepare_manual_allocation(
|
||||
db: Session,
|
||||
*,
|
||||
task_id: int,
|
||||
current: User,
|
||||
) -> dict[str, Any]:
|
||||
"""在短请求内完成人工选号校验,并把任务标记为立即可领取。
|
||||
|
||||
真正的官网账号检测由后台 auto allocator 执行。这样 API 请求不会在多次外部
|
||||
HTTP 调用期间一直持有数据库事务,也不会因为重复点击占满连接池。
|
||||
"""
|
||||
task = _load_task(db, task_id)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
raise HTTPException(status_code=409, detail="已结束任务不能重新分配账号")
|
||||
if not task.commodity_id or not task.required_points:
|
||||
raise HTTPException(status_code=409, detail="请先完成商品映射")
|
||||
if task.account_id and task.lease_id:
|
||||
lease = db.query(AccountLease).filter(AccountLease.id == task.lease_id).first()
|
||||
if lease and lease.status == "active":
|
||||
return get_task_detail(db, task.id)
|
||||
if task.execution_status != "ready":
|
||||
raise HTTPException(status_code=409, detail="只有待分配任务可以重新选号")
|
||||
task.next_allocate_at = _now()
|
||||
task.updated_at = _now()
|
||||
db.flush()
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
|
||||
def allocate_task(db: Session, *, task_id: int, current: User) -> dict[str, Any]:
|
||||
task = _load_task(db, task_id)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
@@ -3310,6 +3338,7 @@ __all__ = [
|
||||
"list_tasks",
|
||||
"mapping_impact",
|
||||
"mark_manual_required",
|
||||
"prepare_manual_allocation",
|
||||
"reconcile_binding_state_outbox",
|
||||
"record_douyu_operation_result",
|
||||
"record_douyu_operation_started",
|
||||
|
||||
Reference in New Issue
Block a user