perf(douyu): 拆分支付轮询并扩展查询并发

This commit is contained in:
yml
2026-11-21 10:38:39 +08:00
parent 743fa69630
commit 3987464035
21 changed files with 1151 additions and 531 deletions
+6
View File
@@ -109,6 +109,10 @@ async def lifespan(app: FastAPI):
start_integration_outbox_worker,
stop_integration_outbox_worker,
)
from .services.payment_poll_scheduler import (
start_payment_poll_scheduler,
stop_payment_poll_scheduler,
)
from .services.platform_fulfillment.auto_allocator import (
start_platform_fulfillment_auto_allocator,
stop_platform_fulfillment_auto_allocator,
@@ -123,9 +127,11 @@ async def lifespan(app: FastAPI):
start_platform_fulfillment_reconciler()
start_platform_fulfillment_auto_allocator()
start_binding_poll_scheduler()
start_payment_poll_scheduler()
try:
yield
finally:
stop_payment_poll_scheduler()
stop_binding_poll_scheduler()
stop_platform_fulfillment_auto_allocator()
stop_platform_fulfillment_reconciler()
+4
View File
@@ -97,6 +97,9 @@ def list_jobs(
from ..services.binding_poll_scheduler import (
scheduler_status as binding_poll_status,
)
from ..services.payment_poll_scheduler import (
scheduler_status as payment_poll_status,
)
from ..services.task_runtime import lane_stats
pending_relogin = count_pending_relogin(db)
@@ -109,6 +112,7 @@ def list_jobs(
if callable(getattr(worker_engine.pool, "status", None))
else "",
"binding_poll": binding_poll_status(),
"payment_poll": payment_poll_status(),
},
"pending_relogin": pending_relogin,
"jobs": [
+6
View File
@@ -180,6 +180,9 @@ async def supplier_recharge_callback(request: Request, db: Session = Depends(get
task.status = "success"
task.message = "供应商直充成功(异步通知)"
task.finished_at = datetime.now(UTC)
task.queue_lane = ""
task.next_run_at = None
task.run_deadline_at = None
if task.account:
task.account.updated_at = datetime.now(UTC)
elif status in {3, 4}:
@@ -190,6 +193,9 @@ async def supplier_recharge_callback(request: Request, db: Session = Depends(get
task.status = "failed"
task.message = reason[:512]
task.finished_at = datetime.now(UTC)
task.queue_lane = ""
task.next_run_at = None
task.run_deadline_at = None
else:
task.status = "running"
task.message = (
+1 -1
View File
@@ -1624,7 +1624,7 @@ class DouyuTaskBatchRequest(BaseModel):
account_ids: list[int]
task_type: str
handbook_scope: str = Field(..., pattern="^(elite|esports|peace)$")
concurrency: int = Field(3, ge=1, le=5)
concurrency: int = Field(3, ge=1, le=10)
payload: dict[str, Any] = Field(default_factory=dict)
platform_task_id: int | None = Field(None, gt=0)
+2 -2
View File
@@ -11,7 +11,7 @@ import threading
from web.backend.database import WorkerSessionLocal
from .douyu_concurrency import clamp_batch_task_concurrency
from .douyu_concurrency import clamp_douyu_task_concurrency
from .douyu_runner import DouyuBatchRunner, douyu_batch_registry
@@ -56,7 +56,7 @@ def start_douyu_batch(
payload=payload,
log_queue=log_queue,
loop=loop,
concurrency=clamp_batch_task_concurrency(concurrency),
concurrency=clamp_douyu_task_concurrency(task_type, concurrency),
)
douyu_batch_registry.register(batch_id, log_queue, loop, runner)
threading.Thread(target=runner.run, daemon=True).start()
+24 -26
View File
@@ -1,14 +1,12 @@
"""斗鱼批次级并发限制。
"""斗鱼批次与任务类型级并发限制。
Process-wide execution is owned by ``task_runtime`` lanes; this module only
keeps the per-batch cap and the overview sub-limit.
Process-wide execution is owned by ``task_runtime`` lanes; this module keeps
per-task-type admission caps before work reaches those lanes.
"""
from __future__ import annotations
import os
import threading
from collections.abc import Callable
def _env_positive_int(name: str, default: int) -> int:
@@ -23,38 +21,38 @@ DOUYU_BATCH_TASK_CONCURRENCY = _env_positive_int(
"DOUYU_BATCH_TASK_CONCURRENCY",
5,
)
DOUYU_MAX_ACTIVE_OVERVIEW_TASKS = _env_positive_int(
"DOUYU_MAX_ACTIVE_OVERVIEW_TASKS",
2,
DOUYU_PAYMENT_QR_CONCURRENCY = _env_positive_int(
"DOUYU_PAYMENT_QR_CONCURRENCY",
10,
)
_overview_slots = threading.BoundedSemaphore(DOUYU_MAX_ACTIVE_OVERVIEW_TASKS)
PAYMENT_QR_TASK_TYPES = frozenset(
{
"create_elite_qr",
"create_esports_qr",
"create_gold_qr",
}
)
def clamp_batch_task_concurrency(value: int) -> int:
return max(1, min(int(value), DOUYU_BATCH_TASK_CONCURRENCY))
def _acquire(slots: threading.BoundedSemaphore, stopped: Callable[[], bool]) -> bool:
while not stopped():
if slots.acquire(timeout=0.2):
return True
return False
def acquire_overview_slot(stopped: Callable[[], bool]) -> bool:
"""等待一个一键查询槽;该限制跨所有批次共享。"""
return _acquire(_overview_slots, stopped)
def release_overview_slot() -> None:
_overview_slots.release()
def clamp_douyu_task_concurrency(task_type: str, value: int) -> int:
"""按任务类型限制批次内并发,不把支付出码压回普通查询的上限。"""
limit = (
DOUYU_PAYMENT_QR_CONCURRENCY
if task_type in PAYMENT_QR_TASK_TYPES
else DOUYU_BATCH_TASK_CONCURRENCY
)
return max(1, min(int(value), limit))
__all__ = [
"DOUYU_BATCH_TASK_CONCURRENCY",
"DOUYU_MAX_ACTIVE_OVERVIEW_TASKS",
"acquire_overview_slot",
"DOUYU_PAYMENT_QR_CONCURRENCY",
"PAYMENT_QR_TASK_TYPES",
"clamp_batch_task_concurrency",
"release_overview_slot",
"clamp_douyu_task_concurrency",
]
+43 -15
View File
@@ -13,10 +13,6 @@ from ..database import WorkerSessionLocal
from ..models import DouyuTask
from .cookie_check_service import check_douyu_cookie
from .douyu_account_probe import persist_probe_result, probe_session
from .douyu_concurrency import (
acquire_overview_slot,
release_overview_slot,
)
from .douyu_runner_bind import BindMixin
from .douyu_runner_core import ( # noqa: F401 (douyu_batch_registry 供 routers 重导出)
DouyuBatchRunnerCore,
@@ -48,18 +44,50 @@ class DouyuBatchRunner(
):
"""批量执行斗鱼活动任务(功能域 Mixin 聚合 + 批次调度)。"""
def poll_payment_task_once(
self,
db,
task: DouyuTask,
account,
config: dict,
) -> None:
cookie = str(account.cookie or "")
result = dict(task.result or {})
if not cookie:
self._mark_task(
db,
task,
"failed",
"账号 Cookie 已失效,无法继续查询支付到账",
result,
)
return
if task.task_type == "create_gold_qr":
self._poll_create_gold_qr_once(db, task, account, cookie, config)
elif task.task_type == "create_elite_qr":
self._poll_create_elite_qr_once(db, task, account, cookie, config)
elif task.task_type == "create_esports_qr":
self._poll_create_esports_qr_once(db, task, account, cookie, config)
else:
self._mark_task(
db,
task,
"failed",
f"不支持的支付轮询任务: {task.task_type}",
result,
)
def mark_payment_poll_timeout(self, db, task: DouyuTask) -> None:
result = dict(task.result or {})
message = {
"create_gold_qr": "鱼翅支付到账查询超时",
"create_elite_qr": "精英宝典开通到账查询超时",
"create_esports_qr": "电竞手册开通到账查询超时",
}.get(task.task_type, "支付到账查询超时")
self._mark_task(db, task, "failed", message, result)
def _execute_one(self, task_id: int, config: dict, total: int):
overview_task = self.task_type == "query_account_overview"
overview_slot = False
if overview_task:
overview_slot = acquire_overview_slot(self._stop.is_set)
if not overview_slot:
return
try:
self._execute_one_with_slot(task_id, config, total)
finally:
if overview_slot:
release_overview_slot()
self._execute_one_with_slot(task_id, config, total)
def _execute_one_with_slot(self, task_id: int, config: dict, total: int):
worker_db = SessionLocal()
+42 -7
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
import asyncio
import threading
import time
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
from typing import TYPE_CHECKING, Any
from loguru import logger
@@ -24,7 +24,7 @@ from ..models import (
ProxyConfig as ProxyConfigModel,
)
from .douyu_account_probe import activity_client
from .douyu_concurrency import clamp_batch_task_concurrency
from .douyu_concurrency import clamp_douyu_task_concurrency
from .douyu_goods_service import upsert_goods_snapshot
from .douyu_service import (
DOUYU_CONFIG_FIELDS,
@@ -114,7 +114,7 @@ class DouyuBatchRunnerCore:
self.payload = payload or {}
self.log_queue = log_queue
self.loop = loop
self.concurrency = clamp_batch_task_concurrency(concurrency)
self.concurrency = clamp_douyu_task_concurrency(task_type, concurrency)
self._stop = threading.Event()
self._counter_lock = threading.Lock()
self._started = 0
@@ -277,8 +277,18 @@ class DouyuBatchRunnerCore:
has_platform_task = task.platform_task_id is not None
task.status = status
task.message = message[:512]
if status in {"success", "failed", "error", "stopped"}:
task.queue_lane = ""
task.next_run_at = None
task.run_deadline_at = None
if result is not None:
task.result = slim_douyu_task_result_for_storage(result)
persisted = dict(result)
if (
status in {"success", "failed", "error", "stopped"}
and "payment_polling" in persisted
):
persisted["payment_polling"] = False
task.result = slim_douyu_task_result_for_storage(persisted)
task.finished_at = datetime.now(UTC)
account = (
db.query(Account).filter(Account.id == task.account_id).first()
@@ -332,6 +342,26 @@ class DouyuBatchRunnerCore:
)
self._sync_platform_fulfillment(task_id, enabled=has_platform_task)
def _schedule_payment_poll(
self,
db: Session,
task: DouyuTask,
result: dict,
message: str,
*,
delay_seconds: int = DOUYU_PAYMENT_POLL_INTERVAL,
) -> None:
"""二维码已生成后释放 worker,由数据库调度器继续查询到账。"""
now = datetime.now(UTC)
result["payment_polling"] = True
task.queue_lane = "payment_poll"
task.next_run_at = now + timedelta(seconds=max(1, int(delay_seconds)))
task.last_run_at = now
if task.run_deadline_at is None:
task.run_deadline_at = now + timedelta(seconds=DOUYU_PAYMENT_POLL_SECONDS)
result["payment_deadline_at"] = task.run_deadline_at.isoformat()
self._update_task_progress(db, task, "running", message, result)
def _update_task_progress(
self,
db: Session,
@@ -428,13 +458,18 @@ class DouyuBatchRunnerCore:
payload = payload_raw if isinstance(payload_raw, dict) else {}
return {**payload, **self.payload}
def _client(self, cookie: str) -> DouyuActivityClient:
def _client(
self,
cookie: str,
*,
direct: bool = False,
) -> DouyuActivityClient:
"""任务 HTTP 客户端:写操作任务注入会话级代理(兑换/锁单/支付/充值/送礼),
读操作任务直连;见 DOUYU_PROXY_TASK_TYPES。"""
读操作任务直连;持久支付轮询显式 ``direct=True``,不能每轮取新代理。"""
return activity_client(
cookie,
logger_callback=lambda msg: self._push_log("debug", msg),
proxies=self._proxies_for_task(),
proxies=None if direct else self._proxies_for_task(),
)
def _sleep_interruptible(self, seconds: float) -> bool:
+194 -175
View File
@@ -3,7 +3,6 @@
from __future__ import annotations
import re
import time
from datetime import UTC, datetime
from decimal import Decimal
from typing import TYPE_CHECKING, Any, cast
@@ -20,7 +19,6 @@ from core.douyu import (
from ..models import Account, DouyuTask
from .business_events import record_recharge
from .douyu_activity_query import query_exchange_balance, query_gold_account
from .douyu_runner_core import DOUYU_PAYMENT_POLL_INTERVAL, DOUYU_PAYMENT_POLL_SECONDS
from .douyu_service import update_account_profile_from_cookie
@@ -33,7 +31,9 @@ class GoldMixin:
@staticmethod
def _to_int(value: Any) -> int | None: ...
def _client(self, cookie: str) -> DouyuActivityClient: ...
def _client(
self, cookie: str, *, direct: bool = False
) -> DouyuActivityClient: ...
def _task_payload(self, task: DouyuTask) -> dict: ...
def _push_log(self, level: str, message: str) -> None: ...
def _mark_task(self, *args: Any, **kwargs: Any) -> None: ...
@@ -55,76 +55,84 @@ class GoldMixin:
"exchange_balance_query": exchange,
}
def _wait_gold_balance_after_payment(
def _poll_create_gold_qr_once(
self,
db: Session,
task: DouyuTask,
account: Account,
client: DouyuActivityClient,
result: dict,
baseline_gold: int | None,
) -> bool:
"""等待鱼翅充值到账;余额变化后写回账号表。"""
deadline = time.monotonic() + DOUYU_PAYMENT_POLL_SECONDS
cookie: str,
config: dict,
) -> None:
"""查询一次鱼翅扫码充值是否到账,然后释放 worker。"""
result = dict(task.result or {})
result["payment_polling"] = True
result["baseline_gold_balance"] = baseline_gold
poll_count = 0
last_gold = baseline_gold
baseline_ready = baseline_gold is not None
while not self._stop.is_set() and time.monotonic() <= deadline:
try:
balance_result = self._refresh_account_gold_balance(client, account)
db.commit()
poll_count += 1
last_gold = balance_result["gold_balance"]
result.update(balance_result)
result["payment_poll_count"] = poll_count
result["payment_polling"] = True
if not baseline_ready and last_gold is not None:
baseline_gold = last_gold
result["baseline_gold_balance"] = baseline_gold
baseline_ready = True
self._update_task_progress(
db,
task,
"running",
f"鱼翅支付码已生成,已记录当前余额 {last_gold},等待到账",
result,
)
if self._stop.wait(DOUYU_PAYMENT_POLL_INTERVAL):
break
continue
# ⚠️ 判据必须是 `>`(余额**增加**)而不是 `!=`。
# 原来用 `!=`,于是余额**下降**也算「到账」:批内并发(concurrency
# 最高 10)时同账号的送礼任务会消耗鱼翅,余额一变就被这个充值任务
# 读成「鱼翅已到账」,往台账里记一笔根本没发生的充值。
changed = last_gold is not None and (
baseline_gold is None or last_gold > baseline_gold
)
if changed:
result["payment_polling"] = False
result["gold_recharged"] = True
return True
self._update_task_progress(
result["payment_poll_count"] = int(result.get("payment_poll_count") or 0) + 1
try:
client = self._client(cookie, direct=True)
balance_result = self._refresh_account_gold_balance(client, account)
db.commit()
result.update(balance_result)
last_gold = balance_result["gold_balance"]
baseline_gold = self._to_int(result.get("baseline_gold_balance"))
if baseline_gold is None:
result["baseline_gold_balance"] = last_gold
self._schedule_payment_poll(
db,
task,
"running",
f"鱼翅支付码已生成,等待到账(当前鱼翅 {last_gold if last_gold is not None else '-'})",
result,
f"鱼翅支付码已生成,已记录当前余额 {last_gold if last_gold is not None else '-'},等待到账",
)
return
# 余额必须增加才算到账,下降可能来自同账号送礼等消费。
if last_gold is not None and last_gold > baseline_gold:
result.pop("payment_poll_error", None)
result["gold_recharged"] = True
result["payment_polling"] = False
amount = int(
result.get("payment_amount")
or self._task_payload(task).get("amount")
or self._task_payload(task).get("gold_amount")
or 1
)
channel = str(
result.get("payment_channel")
or config.get("gold_recharge_channel")
or "wechat_qr"
)
account.updated_at = datetime.now(UTC)
record_recharge(
db,
account,
task_id=task.id,
amount=amount,
channel=channel,
balance_after=account.gold_balance,
confirmed=True,
actor_id=int(task.created_by),
)
self._mark_task(
db,
task,
"success",
f"鱼翅已到账,当前余额: {account.gold_balance if account.gold_balance is not None else '-'}",
result,
)
except Exception as exc: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
poll_count += 1
result["payment_poll_count"] = poll_count
result["payment_poll_error"] = str(exc)
self._update_task_progress(
db, task, "running", f"等待鱼翅到账: {exc}", result
)
if self._stop.wait(DOUYU_PAYMENT_POLL_INTERVAL):
break
result["payment_polling"] = False
result["gold_recharged"] = False
result["gold_balance"] = last_gold
return False
return
result.pop("payment_poll_error", None)
self._schedule_payment_poll(
db,
task,
result,
f"鱼翅支付码已生成,等待到账(当前鱼翅 {last_gold if last_gold is not None else '-'})",
)
except Exception as exc: # noqa: BLE001 外部接口失败继续等待
result["payment_poll_error"] = str(exc)
self._schedule_payment_poll(
db,
task,
result,
f"等待鱼翅到账: {exc}",
)
@staticmethod
def _supplier_value(payload: dict, *keys: str):
@@ -184,65 +192,119 @@ class GoldMixin:
)
return f"DYGF{batch_token}T{task.id}"
def _wait_supplier_gold_order(
def _poll_create_gold_supplier_once(
self,
db: Session,
task: DouyuTask,
client: FishFinRechargeClient,
result: dict,
) -> int | None:
"""轮询供应商直充订单至结束状态。"""
account: Account,
amount: int,
) -> None:
"""查询一次供应商直充订单状态。"""
db.refresh(task)
if task.status in {"success", "failed", "error", "stopped"}:
return
task_id = int(task.id)
result = dict(task.result or {})
order_no = str(result["out_order_id"])
deadline = time.monotonic() + DOUYU_PAYMENT_POLL_SECONDS
poll_count = 0
result["payment_polling"] = True
while not self._stop.is_set() and time.monotonic() <= deadline:
try:
# 回调可能已在另一个数据库会话中结束订单,刷新后直接使用其结果。
db.refresh(task)
if task.status in {"success", "failed"}:
callback_result = (
task.result if isinstance(task.result, dict) else result
)
result.update(callback_result)
result["payment_polling"] = False
return self._supplier_order_status(callback_result)
payload = client.query_order(order_no)
code = self._to_int(self._supplier_value(payload, "code"))
status = self._supplier_order_status(payload)
poll_count += 1
result.update(
{
"payment_poll_count": poll_count,
"supplier_code": code,
"supplier_order_status": status,
"supplier_order": self._supplier_result(payload),
}
result["payment_poll_count"] = int(result.get("payment_poll_count") or 0) + 1
try:
client = FishFinRechargeClient(FishFinRechargeConfig.from_env())
payload = client.query_order(order_no)
code = self._to_int(self._supplier_value(payload, "code"))
status = self._supplier_order_status(payload)
result.update(
{
"supplier_code": code,
"supplier_order_status": status,
"supplier_order": self._supplier_result(payload),
}
)
# 查询期间供应商回调可能已经把任务收口。重新锁行后再决定是否写入,
# 避免长时间 HTTP 调用结束后用旧状态覆盖回调结果。
db.rollback()
locked = (
db.query(DouyuTask)
.filter(
DouyuTask.id == task_id,
DouyuTask.status == "running",
DouyuTask.queue_lane == "payment_poll",
)
if code != 200:
result["payment_polling"] = False
return status if status in {2, 3, 4} else 4
if status in {2, 3, 4}:
result["payment_polling"] = False
return status
self._update_task_progress(
.with_for_update()
.first()
)
if locked is None:
return
task = locked
locked_account = (
db.query(Account).filter(Account.id == task.account_id).first()
)
if locked_account is not None:
account = locked_account
if code != 200:
self._finish_supplier_gold_order(
db,
task,
"running",
f"供应商直充订单处理中(状态 {status if status is not None else '-'})",
account,
result,
amount=amount,
status=(status if status in {2, 3, 4} else 4),
)
except FishFinRechargeError as exc:
poll_count += 1
result["payment_poll_count"] = poll_count
result["payment_poll_error"] = str(exc)
self._update_task_progress(
db, task, "running", f"查询供应商订单失败: {exc}", result
return
if status in {2, 3, 4}:
self._finish_supplier_gold_order(
db,
task,
account,
result,
amount=amount,
status=status,
)
if self._stop.wait(DOUYU_PAYMENT_POLL_INTERVAL):
break
result["payment_polling"] = False
return None
return
result.pop("payment_poll_error", None)
self._schedule_payment_poll(
db,
task,
result,
f"供应商直充订单处理中(状态 {status if status is not None else '-'})",
)
except FishFinRechargeError as exc:
result["payment_poll_error"] = str(exc)
self._schedule_payment_poll(
db,
task,
result,
f"查询供应商订单失败: {exc}",
)
def _finish_supplier_gold_order(
self,
db: Session,
task: DouyuTask,
account: Account,
result: dict,
*,
amount: int,
status: int | None,
) -> None:
if status == 2:
account.updated_at = datetime.now(UTC)
record_recharge(
db,
account,
task_id=task.id,
amount=amount,
order_id=str(result.get("out_order_id") or ""),
supplier_order_id=str(result.get("order_id") or ""),
channel="supplier_api",
douyu_uid=str(result.get("douyu_uid") or ""),
balance_after=account.gold_balance,
actor_id=int(task.created_by),
confirmed=False,
)
self._mark_task(db, task, "success", "供应商直充成功", result)
return
self._mark_task(db, task, "failed", "供应商直充失败", result)
def _execute_create_gold_qr(
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
@@ -271,45 +333,19 @@ class GoldMixin:
result = client.create_gold_qr(
amount=amount, pay_type=int(config["gold_pay_type"])
)
result.update(
{
"payment_amount": amount,
"payment_channel": channel,
"baseline_gold_balance": baseline_gold,
}
)
account.updated_at = datetime.now(UTC)
self._update_task_progress(
db, task, "running", f"鱼翅 {amount} 元支付码已生成,等待到账", result
)
recharged = self._wait_gold_balance_after_payment(
db, task, account, client, result, baseline_gold
)
if self._stop.is_set():
self._mark_task(db, task, "stopped", "任务已停止", result)
return
if recharged:
account.updated_at = datetime.now(UTC)
# 金额用**本地变量 amount**:二维码链路的 result 里没有金额
# (create_gold_qr 只返回 pay_url/token/raw),旧收集器在这里恒写
# amount=None,导致 accounts.recharge_total 系统性少计。
record_recharge(
db,
account,
task_id=task.id,
amount=amount,
channel=channel,
balance_after=account.gold_balance,
confirmed=True,
actor_id=int(task.created_by),
)
self._mark_task(
db,
task,
"success",
f"鱼翅已到账,当前余额: {account.gold_balance if account.gold_balance is not None else '-'}",
result,
)
return
self._mark_task(
self._schedule_payment_poll(
db,
task,
"failed",
f"未检测到鱼翅到账,当前余额: {account.gold_balance if account.gold_balance is not None else '-'}",
result,
f"鱼翅 {amount} 元支付码已生成,等待到账",
)
def _execute_create_gold_supplier_order(
@@ -431,39 +467,22 @@ class GoldMixin:
)
return
account.updated_at = datetime.now(UTC)
self._update_task_progress(
db, task, "running", "供应商直充订单已创建,等待到账", result
)
if status not in {2, 3, 4}:
status = self._wait_supplier_gold_order(db, task, client, result)
if self._stop.is_set():
self._mark_task(db, task, "stopped", "任务已停止", result)
return
if status == 2:
account.updated_at = datetime.now(UTC)
# 幂等键与**供应商回调**(routers/douyu.py)完全一致 —— 两条路径都可能
# 观测到同一笔成功(_wait_supplier_gold_order 会采纳回调结果再 mark 一次),
# 同一个 source_ref 天然去重。
record_recharge(
if status in {2, 3, 4}:
self._finish_supplier_gold_order(
db,
task,
account,
task_id=task.id,
result,
amount=amount,
order_id=str(result.get("out_order_id") or ""),
supplier_order_id=str(result.get("order_id") or ""),
channel="supplier_api",
douyu_uid=str(result.get("douyu_uid") or ""),
balance_after=account.gold_balance,
actor_id=int(task.created_by),
# 供应商终态成功 ≠ 斗鱼余额已变,如实标注
confirmed=False,
status=status,
)
self._mark_task(db, task, "success", "供应商直充成功", result)
return
if status in {3, 4}:
self._mark_task(db, task, "failed", "供应商直充失败", result)
return
self._mark_task(db, task, "failed", "供应商直充订单查询超时", result)
self._schedule_payment_poll(
db,
task,
result,
"供应商直充订单已创建,等待到账",
)
def _execute_query_gold_balance(
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
+177 -218
View File
@@ -2,7 +2,6 @@
from __future__ import annotations
import time
from datetime import UTC, datetime
from typing import TYPE_CHECKING, Any
@@ -17,7 +16,6 @@ from .douyu_elite_status import (
elite_is_currently_open,
normalize_elite_expire_time,
)
from .douyu_runner_core import DOUYU_PAYMENT_POLL_INTERVAL, DOUYU_PAYMENT_POLL_SECONDS
from .douyu_service import account_uid, update_account_profile_from_cookie
@@ -30,11 +28,14 @@ class ManualMixin:
@staticmethod
def _to_int(value: Any) -> int | None: ...
def _client(self, cookie: str) -> DouyuActivityClient: ...
def _client(
self, cookie: str, *, direct: bool = False
) -> DouyuActivityClient: ...
def _task_payload(self, task: DouyuTask) -> dict: ...
def _push_log(self, level: str, message: str) -> None: ...
def _mark_task(self, *args: Any, **kwargs: Any) -> None: ...
def _update_task_progress(self, *args: Any, **kwargs: Any) -> None: ...
def _schedule_payment_poll(self, *args: Any, **kwargs: Any) -> None: ...
@classmethod
def _confirm_act_alias(cls, config: dict) -> str: ...
@@ -136,71 +137,89 @@ class ManualMixin:
result,
)
def _wait_points_after_payment(
def _poll_create_elite_qr_once(
self,
db: Session,
task: DouyuTask,
account: Account,
client: DouyuActivityClient,
cookie: str,
ctn: str,
result: dict,
*,
baseline_points: int | None = None,
) -> bool:
"""等待宝典支付到账。
判定口径是「积分比开通前有增长」:旧口径 `积分 >= 300` 会让账上本来就
有 300+ 积分的账号在出码后第一轮轮询就被判成功,二维码刚弹出来就消失
(线上 2~4 秒 success 的案例都是这种)。拿不到基线时才退回旧口径。
"""
deadline = time.monotonic() + DOUYU_PAYMENT_POLL_SECONDS
config: dict,
) -> None:
"""查询一次精英宝典开通到账。"""
del config
result = dict(task.result or {})
result["payment_polling"] = True
result["payment_target_points"] = 300
result["elite_points_baseline"] = baseline_points
poll_count = 0
last_points = None
while not self._stop.is_set() and time.monotonic() <= deadline:
try:
points_result = self._refresh_account_points(
client, account, cookie, ctn=ctn
result["payment_poll_count"] = int(result.get("payment_poll_count") or 0) + 1
baseline_points = self._to_int(result.get("elite_points_baseline"))
try:
client = self._client(cookie, direct=True)
ctn = str(result.get("payment_ctn") or "")
if not ctn:
ctn = query_csrf(client, refresh_subscribe=True)
result["payment_ctn"] = ctn
points_result = self._refresh_account_points(
client, account, cookie, ctn=ctn
)
db.commit()
last_points = points_result["points"]
result.update(points_result)
arrived = last_points is not None and (
last_points > baseline_points
if baseline_points is not None
else last_points >= 300
)
if arrived:
result.pop("payment_poll_error", None)
result["payment_polling"] = False
result["elite_opened"] = True
account.elite_opened = True
account.updated_at = datetime.now(UTC)
spent = _points_spent(baseline_points, account.points)
emit(
db,
account_id=account.id,
event_type=EVENT_ELITE_OPENED,
title=f"精英宝典开通 -{spent}" if spent else "精英宝典开通",
occurred_at=account.updated_at,
amount=-spent if spent else None,
detail={
"points": account.points,
"expire_time": account.elite_expire_time,
"spent": spent,
},
source="manual",
actor_type="user",
actor_id=int(task.created_by),
source_ref=(
f"elite_opened:{account.id}:"
f"{int(account.updated_at.timestamp())}"
),
)
db.commit()
poll_count += 1
last_points = points_result["points"]
result.update(points_result)
result["payment_poll_count"] = poll_count
result["payment_polling"] = True
if last_points is not None:
arrived = (
last_points > baseline_points
if baseline_points is not None
else last_points >= 300
)
if arrived:
result["payment_polling"] = False
result["elite_opened"] = True
return True
self._update_task_progress(
self._mark_task(
db,
task,
"running",
f"精英宝典支付码已生成,等待开通到账(当前积分 {last_points if last_points is not None else '-'})",
"success",
f"精英宝典已开通,积分: {account.points}",
result,
)
except Exception as exc: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
poll_count += 1
result["payment_poll_count"] = poll_count
result["payment_poll_error"] = str(exc)
self._update_task_progress(
db, task, "running", f"等待开通到账: {exc}", result
)
if self._stop.wait(DOUYU_PAYMENT_POLL_INTERVAL):
break
result["payment_polling"] = False
result["elite_opened"] = False
result["points"] = last_points
return False
return
result.pop("payment_poll_error", None)
self._schedule_payment_poll(
db,
task,
result,
"精英宝典支付码已生成,等待开通到账"
f"(当前积分 {last_points if last_points is not None else '-'})",
)
except Exception as exc: # noqa: BLE001 外部接口失败继续等待
result["payment_poll_error"] = str(exc)
self._schedule_payment_poll(
db,
task,
result,
f"等待精英宝典开通到账: {exc}",
)
def _refresh_esports_handbook(
self,
@@ -238,76 +257,97 @@ class ManualMixin:
"points": manual_score,
}
def _wait_esports_open_after_payment(
def _poll_create_esports_qr_once(
self,
db: Session,
task: DouyuTask,
account: Account,
client: DouyuActivityClient,
*,
manual_id: str,
result: dict,
baseline_manual_type: int | None,
baseline_manual_score: int | None,
) -> bool:
"""等待电竞手册支付到账,以 manualType=1 或积分变化作为成功条件。"""
deadline = time.monotonic() + DOUYU_PAYMENT_POLL_SECONDS
cookie: str,
config: dict,
) -> None:
"""查询一次电竞手册开通到账。"""
result = dict(task.result or {})
result["payment_polling"] = True
result["esports_manual_type_baseline"] = baseline_manual_type
result["esports_manual_score_baseline"] = baseline_manual_score
poll_count = 0
last_manual_type = baseline_manual_type
last_manual_score = baseline_manual_score
while not self._stop.is_set() and time.monotonic() <= deadline:
try:
handbook_result = self._refresh_esports_handbook(
client,
account,
manual_id=manual_id,
result["payment_poll_count"] = int(result.get("payment_poll_count") or 0) + 1
manual_id = str(
result.get("payment_manual_id") or config.get("esports_manual_id") or ""
).strip()
baseline_manual_score = self._to_int(
result.get("esports_manual_score_baseline")
)
if not manual_id:
self._mark_task(
db,
task,
"failed",
"请先配置电竞手册 manualID",
result,
)
return
try:
client = self._client(cookie, direct=True)
handbook_result = self._refresh_esports_handbook(
client,
account,
manual_id=manual_id,
)
db.commit()
last_manual_type = handbook_result["esports_manual_type"]
last_manual_score = handbook_result["esports_manual_score"]
result.update(handbook_result)
opened = (last_manual_type is not None and last_manual_type >= 1) or (
baseline_manual_score is not None
and last_manual_score is not None
and last_manual_score > baseline_manual_score
)
if opened:
result.pop("payment_poll_error", None)
result["payment_polling"] = False
result["esports_opened"] = True
account.updated_at = datetime.now(UTC)
spent = _points_spent(baseline_manual_score, account.esports_points)
emit(
db,
account_id=account.id,
event_type=EVENT_ESPORTS_OPENED,
title=f"电竞手册开通 -{spent}" if spent else "电竞手册开通",
occurred_at=account.updated_at,
amount=-spent if spent else None,
detail={"points": account.esports_points, "spent": spent},
source="manual",
actor_type="user",
actor_id=int(task.created_by),
source_ref=(
f"esports_opened:{account.id}:"
f"{int(account.updated_at.timestamp())}"
),
)
db.commit()
poll_count += 1
last_manual_type = handbook_result["esports_manual_type"]
last_manual_score = handbook_result["esports_manual_score"]
result.update(handbook_result)
result["payment_poll_count"] = poll_count
result["payment_polling"] = True
opened = (last_manual_type is not None and last_manual_type >= 1) or (
baseline_manual_score is not None
and last_manual_score is not None
and last_manual_score > baseline_manual_score
)
if opened:
result["payment_polling"] = False
result["esports_opened"] = True
return True
self._update_task_progress(
self._mark_task(
db,
task,
"running",
"电竞手册支付码已生成,等待开通到账"
f"(类型 {last_manual_type if last_manual_type is not None else '-'},"
f"积分 {last_manual_score if last_manual_score is not None else '-'})",
"success",
"电竞手册已开通,积分: "
f"{account.esports_points if account.esports_points is not None else '-'}",
result,
)
except Exception as exc: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
poll_count += 1
result["payment_poll_count"] = poll_count
result["payment_poll_error"] = str(exc)
self._update_task_progress(
db, task, "running", f"等待电竞手册到账: {exc}", result
)
if self._stop.wait(DOUYU_PAYMENT_POLL_INTERVAL):
break
result["payment_polling"] = False
result["esports_opened"] = False
result["esports_manual_type"] = last_manual_type
result["esports_manual_score"] = last_manual_score
result["esports_points"] = last_manual_score
result["points"] = last_manual_score
return False
return
result.pop("payment_poll_error", None)
self._schedule_payment_poll(
db,
task,
result,
"电竞手册支付码已生成,等待开通到账"
f"(类型 {last_manual_type if last_manual_type is not None else '-'},"
f"积分 {last_manual_score if last_manual_score is not None else '-'})",
)
except Exception as exc: # noqa: BLE001 外部接口失败继续等待
result["payment_poll_error"] = str(exc)
self._schedule_payment_poll(
db,
task,
result,
f"等待电竞手册开通到账: {exc}",
)
def _execute_create_elite_qr(
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
@@ -378,60 +418,20 @@ class ManualMixin:
amount=int(config["elite_amount"]),
room_id=str(config["room_id"]),
)
result.update(
{
"payment_ctn": ctn,
"elite_points_baseline": baseline_points,
"payment_manual_id": manual_id,
"payment_rid": str(config.get("rid") or ""),
}
)
account.updated_at = datetime.now(UTC)
self._update_task_progress(
db, task, "running", "精英宝典支付码已生成,等待开通到账", result
)
opened = self._wait_points_after_payment(
self._schedule_payment_poll(
db,
task,
account,
client,
cookie,
ctn,
result,
baseline_points=baseline_points,
)
if self._stop.is_set():
self._mark_task(db, task, "stopped", "任务已停止", result)
return
if opened:
account.elite_opened = True
account.updated_at = datetime.now(UTC)
# elite_opened 是**覆盖式**布尔值:开通之后再操作也看不出「什么时候开的」。
# 在这里记一条事件,补上开通时间。
# 开通是**资产减少**(花积分)。只记余额、不记花掉多少的话,
# 账号的积分流水就对不上账 —— 进项有金额、出项没有。
spent = _points_spent(baseline_points, account.points)
emit(
db,
account_id=account.id,
event_type=EVENT_ELITE_OPENED,
title=f"精英宝典开通 -{spent}" if spent else "精英宝典开通",
occurred_at=account.updated_at,
amount=-spent if spent else None,
detail={
"points": account.points,
"expire_time": account.elite_expire_time,
"spent": spent,
},
source="manual",
actor_type="user",
actor_id=int(task.created_by),
source_ref=(
f"elite_opened:{account.id}:{int(account.updated_at.timestamp())}"
),
)
self._mark_task(
db, task, "success", f"精英宝典已开通,积分: {account.points}", result
)
return
self._mark_task(
db,
task,
"failed",
f"未检测到精英宝典开通到账,当前积分: {account.points if account.points is not None else '-'}",
result,
"精英宝典支付码已生成,等待开通到账",
)
def _execute_create_esports_qr(
@@ -487,62 +487,21 @@ class ManualMixin:
amount=int(config["esports_amount"]),
room_id=str(config["room_id"]),
)
result.update(baseline_result)
result.update(
{
**baseline_result,
"payment_ctn": ctn,
"payment_manual_id": manual_id,
"esports_manual_type_baseline": baseline_manual_type,
"esports_manual_score_baseline": baseline_manual_score,
}
)
account.updated_at = datetime.now(UTC)
self._update_task_progress(
db, task, "running", "电竞手册支付码已生成,等待开通到账", result
)
opened = self._wait_esports_open_after_payment(
self._schedule_payment_poll(
db,
task,
account,
client,
manual_id=manual_id,
result=result,
baseline_manual_type=baseline_manual_type,
baseline_manual_score=baseline_manual_score,
)
if self._stop.is_set():
self._mark_task(db, task, "stopped", "任务已停止", result)
return
if opened:
account.updated_at = datetime.now(UTC)
# 与精英宝典同理:状态字段是覆盖式的,这里补上「什么时候开的」。
# 注意只在**真正开通**这一支发事件;上面「基线查到已开通」那一支是检测,
# 每次都发会刷屏。
# 同理:开通电竞手册也要记清花了多少积分
spent = _points_spent(baseline_manual_score, account.esports_points)
emit(
db,
account_id=account.id,
event_type=EVENT_ESPORTS_OPENED,
title=f"电竞手册开通 -{spent}" if spent else "电竞手册开通",
occurred_at=account.updated_at,
amount=-spent if spent else None,
detail={"points": account.esports_points, "spent": spent},
source="manual",
actor_type="user",
actor_id=int(task.created_by),
source_ref=(
f"esports_opened:{account.id}:{int(account.updated_at.timestamp())}"
),
)
self._mark_task(
db,
task,
"success",
f"电竞手册已开通,积分: {account.esports_points if account.esports_points is not None else '-'}",
result,
)
return
self._mark_task(
db,
task,
"failed",
"未检测到电竞手册开通到账"
f",类型: {result.get('esports_manual_type', '-')},"
f"积分: {result.get('esports_manual_score', '-')}",
result,
"电竞手册支付码已生成,等待开通到账",
)
def _execute_query_esports_points(
+18 -10
View File
@@ -469,17 +469,25 @@ def cleanup_orphan_douyu_tasks(
query = query.filter(~DouyuTask.batch_id.in_(list(active_batch_ids)))
now = datetime.now(UTC)
# Scan waits are durable. A restarted scheduler can resume them from the
# database, so startup cleanup must not turn them into stopped tasks.
query = query.filter(
or_(
DouyuTask.task_type != "get_bind_qr",
DouyuTask.queue_lane != "binding_poll",
DouyuTask.next_run_at.is_(None),
DouyuTask.run_deadline_at.is_(None),
DouyuTask.run_deadline_at <= now,
)
# Scan and payment waits are durable. A restarted scheduler can resume them
# from the database, so startup cleanup must not stop unexpired rows.
durable_binding = and_(
DouyuTask.task_type == "get_bind_qr",
DouyuTask.queue_lane == "binding_poll",
DouyuTask.next_run_at.isnot(None),
DouyuTask.run_deadline_at.isnot(None),
DouyuTask.run_deadline_at > now,
)
durable_payment = and_(
DouyuTask.task_type.in_(
{"create_elite_qr", "create_esports_qr", "create_gold_qr"}
),
DouyuTask.queue_lane == "payment_poll",
DouyuTask.next_run_at.isnot(None),
DouyuTask.run_deadline_at.isnot(None),
DouyuTask.run_deadline_at > now,
)
query = query.filter(~or_(durable_binding, durable_payment))
tasks = query.all()
if not tasks:
@@ -0,0 +1,269 @@
"""Database-backed scheduler for generated payment QR codes."""
from __future__ import annotations
import os
import threading
from concurrent.futures import Future
from datetime import UTC, datetime, timedelta
from loguru import logger
from sqlalchemy.orm import joinedload
from ..database import WorkerSessionLocal
from ..models import DouyuTask
from .douyu_runner import DouyuBatchRunner
from .douyu_runner_core import DOUYU_PAYMENT_POLL_INTERVAL
from .task_runtime import TaskLane, submit
DEFAULT_INTERVAL_SECONDS = 1
DEFAULT_BATCH_SIZE = 30
CLAIM_SECONDS = 60
PAYMENT_TASK_TYPES = frozenset(
{
"create_elite_qr",
"create_esports_qr",
"create_gold_qr",
}
)
_stop_event = threading.Event()
_thread: threading.Thread | None = None
_lock = threading.Lock()
_in_flight: set[int] = set()
_in_flight_lock = threading.Lock()
def _env_int(name: str, default: int, minimum: int, maximum: int) -> int:
try:
value = int(os.getenv(name, str(default)))
except ValueError:
return default
return max(minimum, min(maximum, value))
def _claim_due_payment_tasks(limit: int) -> list[int]:
db = WorkerSessionLocal()
now = datetime.now(UTC)
claimed: list[int] = []
try:
rows = (
db.query(DouyuTask)
.filter(
DouyuTask.task_type.in_(PAYMENT_TASK_TYPES),
DouyuTask.status == "running",
DouyuTask.queue_lane == "payment_poll",
DouyuTask.next_run_at.isnot(None),
DouyuTask.next_run_at <= now,
DouyuTask.run_deadline_at.isnot(None),
)
.order_by(DouyuTask.next_run_at.asc(), DouyuTask.id.asc())
.with_for_update(skip_locked=True)
.limit(limit)
.all()
)
for row in rows:
task_id = int(row.id)
with _in_flight_lock:
if task_id in _in_flight:
continue
_in_flight.add(task_id)
row.next_run_at = now + timedelta(seconds=CLAIM_SECONDS)
row.last_run_at = now
row.attempt_count = int(row.attempt_count or 0) + 1
claimed.append(task_id)
db.commit()
return claimed
except Exception:
db.rollback()
with _in_flight_lock:
for task_id in claimed:
_in_flight.discard(task_id)
raise
finally:
db.close()
def _reschedule_after_error(
db,
task: DouyuTask,
account,
exc: Exception,
) -> None:
result = dict(task.result or {})
result["payment_poll_error"] = str(exc)
runner = DouyuBatchRunner(
db,
task.batch_id,
task.task_type,
close_db=False,
)
runner._schedule_payment_poll(
db,
task,
result,
f"支付到账查询失败,稍后重试: {exc}",
delay_seconds=DOUYU_PAYMENT_POLL_INTERVAL,
)
if account is not None:
logger.warning(
"[douyu] 支付轮询失败 task_id={} account_id={}: {}",
task.id,
account.id,
exc,
)
def poll_payment_task_once(task_id: int) -> None:
db = WorkerSessionLocal()
task = None
account = None
try:
task = (
db.query(DouyuTask)
.options(joinedload(DouyuTask.account))
.filter(DouyuTask.id == int(task_id))
.first()
)
if (
task is None
or task.status != "running"
or task.task_type not in PAYMENT_TASK_TYPES
or task.queue_lane != "payment_poll"
):
return
account = task.account
if account is None:
DouyuBatchRunner(
db,
task.batch_id,
task.task_type,
close_db=False,
)._mark_task(
db,
task,
"failed",
"账号不存在,无法继续查询支付到账",
dict(task.result or {}),
)
return
runner = DouyuBatchRunner(
db,
task.batch_id,
task.task_type,
close_db=False,
)
now = datetime.now(UTC)
if task.run_deadline_at is not None and task.run_deadline_at <= now:
runner.mark_payment_poll_timeout(db, task)
return
config = runner._config_info(db)
runner.poll_payment_task_once(db, task, account, config)
except Exception as exc: # noqa: BLE001 - durable row is retried after backoff
db.rollback()
if task is not None:
try:
db.refresh(task)
if task.status == "running" and task.queue_lane == "payment_poll":
_reschedule_after_error(db, task, account, exc)
except Exception: # noqa: BLE001 - scheduler must survive one bad row
logger.exception("[douyu] 支付轮询失败后重排也失败 task_id={}", task_id)
finally:
db.close()
with _in_flight_lock:
_in_flight.discard(int(task_id))
def _release_callback(future: Future) -> None:
try:
future.result()
except Exception as exc: # noqa: BLE001 - worker already logs; keep scheduler alive
logger.warning("支付到账查询任务异常: {}", exc)
def run_payment_poll_dispatch_once(limit: int = DEFAULT_BATCH_SIZE) -> int:
claimed = _claim_due_payment_tasks(max(1, limit))
submitted = 0
for task_id in claimed:
future = submit(
TaskLane.PAYMENT_POLL,
poll_payment_task_once,
task_id,
stopped=_stop_event.is_set,
)
if future is None:
with _in_flight_lock:
_in_flight.discard(task_id)
break
future.add_done_callback(_release_callback)
submitted += 1
return submitted
def _run() -> None:
interval = _env_int(
"PAYMENT_POLL_DISPATCH_SECONDS",
DEFAULT_INTERVAL_SECONDS,
1,
30,
)
while not _stop_event.is_set():
try:
batch_size = _env_int(
"PAYMENT_POLL_DISPATCH_BATCH",
DEFAULT_BATCH_SIZE,
1,
200,
)
run_payment_poll_dispatch_once(batch_size)
except Exception as exc: # noqa: BLE001 - scheduler survives any one bad tick
logger.warning("支付到账调度轮次失败: {}", exc)
_stop_event.wait(interval)
def start_payment_poll_scheduler() -> bool:
global _thread
with _lock:
if _thread is not None and _thread.is_alive():
return False
_stop_event.clear()
_thread = threading.Thread(
target=_run,
name="payment-poll-scheduler",
daemon=True,
)
_thread.start()
logger.info("支付到账定时调度器已启动")
return True
def stop_payment_poll_scheduler() -> None:
global _thread
_stop_event.set()
with _lock:
thread = _thread
_thread = None
if thread is not None and thread.is_alive():
thread.join(timeout=3)
def scheduler_status() -> dict[str, object]:
with _lock:
running = _thread is not None and _thread.is_alive()
with _in_flight_lock:
in_flight = len(_in_flight)
return {
"running": running,
"in_flight": in_flight,
"claim_seconds": CLAIM_SECONDS,
}
__all__ = [
"PAYMENT_TASK_TYPES",
"poll_payment_task_once",
"run_payment_poll_dispatch_once",
"scheduler_status",
"start_payment_poll_scheduler",
"stop_payment_poll_scheduler",
]
+9 -3
View File
@@ -23,9 +23,11 @@ class TaskLane(StrEnum):
LOGIN = "login"
ACCOUNT_CHECK = "account_check"
AUTOMATION = "automation"
OVERVIEW_QUERY = "overview_query"
QUERY_BATCH = "query_batch"
COLLAB_RECOMMEND = "collab_recommend"
PAYMENT_WAIT = "payment_wait"
PAYMENT_QR = "payment_qr"
PAYMENT_POLL = "payment_poll"
OPS_WRITE = "ops_write"
HUYA_BATCH = "huya_batch"
HUYA_REGISTER = "huya_register"
@@ -53,9 +55,11 @@ _DEFAULT_WORKERS: dict[TaskLane, int] = {
TaskLane.LOGIN: 4,
TaskLane.ACCOUNT_CHECK: 4,
TaskLane.AUTOMATION: 2,
TaskLane.OVERVIEW_QUERY: _env_int("DOUYU_MAX_ACTIVE_OVERVIEW_TASKS", 5),
TaskLane.QUERY_BATCH: 3,
TaskLane.COLLAB_RECOMMEND: 2,
TaskLane.PAYMENT_WAIT: 2,
TaskLane.PAYMENT_QR: 10,
TaskLane.PAYMENT_POLL: 3,
TaskLane.OPS_WRITE: 2,
TaskLane.HUYA_BATCH: 2,
TaskLane.HUYA_REGISTER: 2,
@@ -154,6 +158,8 @@ def shutdown(wait: bool = False) -> None:
def douyu_lane_for_task(task_type: str) -> TaskLane:
if task_type == "query_account_overview":
return TaskLane.OVERVIEW_QUERY
if task_type in {
"get_bind_qr",
"confirm_bind",
@@ -171,7 +177,7 @@ def douyu_lane_for_task(task_type: str) -> TaskLane:
"create_esports_qr",
"create_gold_qr",
}:
return TaskLane.PAYMENT_WAIT
return TaskLane.PAYMENT_QR
if task_type in {
"lock_goods",
"pay_locked_order",