修复虎牙任务台卡死与轮询过重,并调整默认端口

默认端口改为后端 8800 / 前端 5174,避免多项目冲突。
清理无执行器的残留 running 任务,支持停止无效批次;绑定二维码结果页不再被假活跃批次锁死。
任务列表默认剥离 base64 小程序码,按需拉取详情,空闲轮询降频,显著降低 tasks 请求体积。
This commit is contained in:
yml2213
2026-07-24 11:38:07 +08:00
parent 69b6120ede
commit 9ec4bba0a9
13 changed files with 430 additions and 181 deletions
+34
View File
@@ -313,6 +313,40 @@ def ensure_huya_config(db: Session) -> HuyaConfig:
return config
HUYA_ACTIVE_TASK_STATUSES = ("planned", "pending", "running")
HUYA_STALE_TASK_STATUSES = ("pending", "running")
def cleanup_orphan_huya_tasks(
db: Session,
*,
active_batch_ids: set[str] | None = None,
batch_id: str | None = None,
statuses: tuple[str, ...] = HUYA_ACTIVE_TASK_STATUSES,
message: str = "任务已中断(服务重启或批次丢失)",
) -> int:
"""清理没有执行器接管的虎牙任务,避免前端被历史 running 状态锁死。"""
query = db.query(HuyaTask).filter(HuyaTask.status.in_(statuses))
if batch_id:
query = query.filter(HuyaTask.batch_id == batch_id)
elif active_batch_ids is not None:
if active_batch_ids:
query = query.filter(~HuyaTask.batch_id.in_(list(active_batch_ids)))
# active_batch_ids is None 且未指定 batch_id:清理全部匹配状态
tasks = query.all()
if not tasks:
return 0
now = datetime.now(timezone.utc)
for task in tasks:
task.status = "stopped"
task.message = message
task.finished_at = now
db.commit()
return len(tasks)
def create_planned_tasks(
db: Session,
account_ids: list[int],