perf(douyu): 拆分任务槽并改造绑定扫码调度

This commit is contained in:
yml
2026-11-20 22:03:20 +08:00
parent 8869e427d2
commit 071d45ad1d
40 changed files with 1635 additions and 245 deletions
+14 -2
View File
@@ -7,7 +7,7 @@ import uuid
from datetime import UTC, datetime
from loguru import logger
from sqlalchemy import and_, func, select
from sqlalchemy import and_, func, or_, select
from sqlalchemy.orm import Session
from core.douyu.cookie_utils import cookie_value
@@ -468,10 +468,22 @@ def cleanup_orphan_douyu_tasks(
elif active_batch_ids is not None and active_batch_ids:
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,
)
)
tasks = query.all()
if not tasks:
return 0
now = datetime.now(UTC)
account_ids = {int(task.account_id) for task in tasks if task.account_id}
accounts = (
{