feat(fulfillment): 新增直播账号履约工作台
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""在后台线程启动斗鱼任务批次。
|
||||
|
||||
任务创建入口和执行入口分离,供旧工作台和直播账号履约共用同一套线程/注册表。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import threading
|
||||
|
||||
from web.backend.database import SessionLocal
|
||||
|
||||
from .douyu_runner import DouyuBatchRunner, douyu_batch_registry
|
||||
|
||||
|
||||
def start_douyu_batch(
|
||||
*,
|
||||
batch_id: str,
|
||||
task_type: str,
|
||||
payload: dict,
|
||||
concurrency: int,
|
||||
) -> None:
|
||||
"""必须在运行中的 asyncio 事件循环里调用。"""
|
||||
log_queue = asyncio.Queue()
|
||||
loop = asyncio.get_running_loop()
|
||||
thread_db = SessionLocal()
|
||||
runner = DouyuBatchRunner(
|
||||
db=thread_db,
|
||||
batch_id=batch_id,
|
||||
task_type=task_type,
|
||||
payload=payload,
|
||||
log_queue=log_queue,
|
||||
loop=loop,
|
||||
concurrency=max(1, min(int(concurrency), 10)),
|
||||
)
|
||||
douyu_batch_registry.register(batch_id, log_queue, loop, runner)
|
||||
threading.Thread(target=runner.run, daemon=True).start()
|
||||
|
||||
|
||||
__all__ = ["start_douyu_batch"]
|
||||
Reference in New Issue
Block a user