perf(douyu): 拆分支付轮询并扩展查询并发
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user