perf(douyu): 限制任务并发并释放长事务连接
This commit is contained in:
@@ -12,6 +12,12 @@ from ..database import SessionLocal
|
||||
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,
|
||||
acquire_running_task_slot,
|
||||
release_overview_slot,
|
||||
release_running_task_slot,
|
||||
)
|
||||
from .douyu_runner_bind import BindMixin
|
||||
from .douyu_runner_core import ( # noqa: F401 (douyu_batch_registry 供 routers 重导出)
|
||||
DouyuBatchRunnerCore,
|
||||
@@ -39,6 +45,25 @@ class DouyuBatchRunner(
|
||||
"""批量执行斗鱼活动任务(功能域 Mixin 聚合 + 批次调度)。"""
|
||||
|
||||
def _execute_one(self, task_id: int, config: dict, total: int):
|
||||
overview_task = self.task_type == "query_account_overview"
|
||||
overview_slot = False
|
||||
running_slot = False
|
||||
if overview_task:
|
||||
overview_slot = acquire_overview_slot(self._stop.is_set)
|
||||
if not overview_slot:
|
||||
return
|
||||
try:
|
||||
running_slot = acquire_running_task_slot(self._stop.is_set)
|
||||
if not running_slot:
|
||||
return
|
||||
self._execute_one_with_slot(task_id, config, total)
|
||||
finally:
|
||||
if running_slot:
|
||||
release_running_task_slot()
|
||||
if overview_slot:
|
||||
release_overview_slot()
|
||||
|
||||
def _execute_one_with_slot(self, task_id: int, config: dict, total: int):
|
||||
worker_db = SessionLocal()
|
||||
try:
|
||||
task = (
|
||||
|
||||
Reference in New Issue
Block a user