重构虎牙精英宝典协议与支付状态链路

This commit is contained in:
yml2213
2026-09-01 11:31:15 +08:00
parent 955ba45488
commit 684e16a07a
12 changed files with 937 additions and 51 deletions
+30
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
import copy
import threading
import time
from datetime import UTC, datetime
@@ -130,6 +131,7 @@ class HuyaBatchRunnerCore:
task.result = result
task.finished_at = datetime.now(UTC)
worker_db.commit()
self._push_task_event(task)
def _update_task_progress(
self,
@@ -144,6 +146,34 @@ class HuyaBatchRunnerCore:
if result is not None:
task.result = result
worker_db.commit()
self._push_task_event(task)
def _push_task_event(self, task: HuyaTask) -> None:
"""向批次 WS 推送任务状态;二维码图片留给详情接口按需读取。"""
if not self.log_queue or not self.loop:
return
result = copy.deepcopy(task.result) if isinstance(task.result, dict) else None
if result and isinstance(result.get("mini_qrcode_image"), str):
result.pop("mini_qrcode_image", None)
result["has_mini_qrcode"] = True
event = {
"level": "task",
"message": "",
"task": {
"id": task.id,
"batch_id": task.batch_id,
"account_id": task.account_id,
"task_type": task.task_type,
"handbook_scope": getattr(task, "handbook_scope", "legacy") or "legacy",
"status": task.status or "",
"message": task.message or "",
"result": result,
"created_by": task.created_by,
"created_at": task.created_at.isoformat() if task.created_at else None,
"finished_at": task.finished_at.isoformat() if task.finished_at else None,
},
}
asyncio.run_coroutine_threadsafe(self.log_queue.put(event), self.loop)
class HuyaBatchRegistry: