perf(douyu): 拆分任务槽并改造绑定扫码调度
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from concurrent.futures import as_completed
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
@@ -34,6 +34,7 @@ from ...douyu_account_probe import (
|
||||
probe_session,
|
||||
)
|
||||
from ...douyu_service import cookie_holding_filter, cookie_operable_filter
|
||||
from ...task_runtime import TaskLane, submit
|
||||
|
||||
JOB_KEY = "ck_health"
|
||||
FLUSH_EVERY = 25
|
||||
@@ -146,11 +147,14 @@ def run_ck_health(db: Session, job: AutomationJob) -> dict[str, Any]:
|
||||
|
||||
results: dict[int, dict[str, Any]] = {}
|
||||
concurrency = max(min(int(job.concurrency or 1), 16), 1)
|
||||
with ThreadPoolExecutor(max_workers=concurrency) as pool:
|
||||
futures = {pool.submit(_detect, account): account for account in accounts}
|
||||
for future in as_completed(futures):
|
||||
account = futures[future]
|
||||
results[account.id] = future.result()
|
||||
futures = {}
|
||||
for account in accounts:
|
||||
future = submit(TaskLane.ACCOUNT_CHECK, _detect, account)
|
||||
if future is not None:
|
||||
futures[future] = account
|
||||
for future in as_completed(futures):
|
||||
account = futures[future]
|
||||
results[account.id] = future.result()
|
||||
|
||||
# 只写检测结果三件套;cookie / status / attempt_* 一律不动。
|
||||
valid = invalid = errors = 0
|
||||
|
||||
@@ -20,7 +20,7 @@ from typing import Any
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ....database import SessionLocal
|
||||
from ....database import WorkerSessionLocal
|
||||
from ....models import Account, AutomationJob, LoginTask, User
|
||||
from ....models import ProxyConfig as ProxyConfigModel
|
||||
from ...account_events_service import EVENT_RELOGIN_FAILED, emit
|
||||
@@ -148,7 +148,7 @@ def settle_fresh_results(
|
||||
退避时间,其中 2 条还被标成「极验」进了待人工队列。SQLite 的读一致性与 MySQL
|
||||
不同,这类问题在 SQLite 上复现不出来。
|
||||
"""
|
||||
session = SessionLocal()
|
||||
session = WorkerSessionLocal()
|
||||
try:
|
||||
fresh, order = _load_batch_state(session, batch_id)
|
||||
counters = settle_results(
|
||||
@@ -241,7 +241,7 @@ def run_ck_relogin(db: Session, job: AutomationJob) -> dict[str, Any]:
|
||||
_, max_total_time = get_relogin_limits()
|
||||
|
||||
# 批次用独立会话(runner 会在自己的线程/会话里写库),跑完再回来读结果。
|
||||
runner_db = SessionLocal()
|
||||
runner_db = WorkerSessionLocal()
|
||||
runner = LoginBatchRunner(
|
||||
db=runner_db,
|
||||
account_ids=account_ids,
|
||||
|
||||
Reference in New Issue
Block a user