feat(douyu): 隔离充值会话并阻止同账号并发充值
This commit is contained in:
@@ -62,7 +62,9 @@ from ..services.douyu_runner import DouyuBatchRunner, douyu_batch_registry
|
||||
from ..services.douyu_service import (
|
||||
DOUYU_CONFIG_FIELDS,
|
||||
DOUYU_HANDBOOK_TASK_TYPES,
|
||||
DOUYU_ACTIVE_TASK_STATUSES,
|
||||
SUPPORTED_DOUYU_TASK_TYPES,
|
||||
DouyuActivePaymentError,
|
||||
apply_douyu_config_defaults,
|
||||
cleanup_orphan_douyu_tasks,
|
||||
cookie_holding_filter,
|
||||
@@ -294,8 +296,8 @@ def _require_task_account_access(
|
||||
|
||||
|
||||
def _require_batch_owner(db: Session, current: User, batch_id: str) -> None:
|
||||
"""客服只能停止或订阅自己创建的任务批次。"""
|
||||
if _can_view_all(current):
|
||||
"""除超级管理员外,只能停止或订阅自己创建的任务批次。"""
|
||||
if current.role == "super_admin":
|
||||
return
|
||||
exists = (
|
||||
db.query(DouyuTask.id)
|
||||
@@ -819,7 +821,7 @@ async def create_task_batch(
|
||||
cleanup_orphan_douyu_tasks(
|
||||
db,
|
||||
active_batch_ids=douyu_batch_registry.active_ids(),
|
||||
statuses=("pending", "running"),
|
||||
statuses=DOUYU_ACTIVE_TASK_STATUSES,
|
||||
message="任务已中断(无执行器接管)",
|
||||
)
|
||||
|
||||
@@ -833,6 +835,8 @@ async def create_task_batch(
|
||||
req.payload,
|
||||
platform_task_id=req.platform_task_id,
|
||||
)
|
||||
except DouyuActivePaymentError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
if count == 0:
|
||||
@@ -976,7 +980,7 @@ def cleanup_orphan_tasks(
|
||||
cleaned = cleanup_orphan_douyu_tasks(
|
||||
db,
|
||||
active_batch_ids=douyu_batch_registry.active_ids(),
|
||||
statuses=("pending", "running"),
|
||||
statuses=DOUYU_ACTIVE_TASK_STATUSES,
|
||||
message="任务已中断(无执行器接管)",
|
||||
)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user