fix(douyu): 对齐绑定小程序码并修复残留任务停止

This commit is contained in:
yml
2026-11-22 22:15:48 +08:00
parent 5393b668e0
commit d315e983f6
9 changed files with 409 additions and 38 deletions
+8 -2
View File
@@ -1612,7 +1612,10 @@ def stop_batch(
if batch.get("finished"):
douyu_batch_registry.pop(batch_id)
cleaned = cleanup_orphan_douyu_tasks(
db, batch_id=batch_id, message="批次已结束"
db,
batch_id=batch_id,
include_durable=True,
message="批次已结束",
)
if cleaned:
return {
@@ -1633,7 +1636,10 @@ def stop_batch(
return {"message": "已发送停止信号", "success": True}
cleaned = cleanup_orphan_douyu_tasks(
db, batch_id=batch_id, message="任务已停止(批次不存在)"
db,
batch_id=batch_id,
include_durable=True,
message="任务已停止(批次不存在)",
)
if cleaned:
if is_recharge_batch:
+16 -2
View File
@@ -422,9 +422,14 @@ def cleanup_orphan_douyu_tasks(
active_batch_ids: set[str] | None = None,
batch_id: str | None = None,
statuses: tuple[str, ...] = DOUYU_ACTIVE_TASK_STATUSES,
include_durable: bool = False,
message: str = "任务已中断(服务重启或批次丢失)",
) -> int:
"""清理没有执行器接管的斗鱼任务。"""
"""清理没有执行器接管的斗鱼任务。
启动清理默认保留仍可恢复的扫码/支付轮询;用户主动停止时传
``include_durable=True``,确保内存注册表丢失后也能终止残留轮询。
"""
query = db.query(DouyuTask).filter(DouyuTask.status.in_(statuses))
if batch_id:
query = query.filter(DouyuTask.batch_id == batch_id)
@@ -451,7 +456,8 @@ def cleanup_orphan_douyu_tasks(
DouyuTask.run_deadline_at.isnot(None),
DouyuTask.run_deadline_at > now,
)
query = query.filter(~or_(durable_binding, durable_payment))
if not include_durable:
query = query.filter(~or_(durable_binding, durable_payment))
tasks = query.all()
if not tasks:
@@ -471,6 +477,8 @@ def cleanup_orphan_douyu_tasks(
task.status = "stopped"
task.message = message
task.finished_at = now
task.queue_lane = ""
task.next_run_at = None
account = accounts.get(int(task.account_id)) if task.account_id else None
if account is not None:
event_contexts.append(
@@ -590,6 +598,12 @@ def sanitize_douyu_task_result(
data = strip_douyu_raw_snapshots(result)
if not isinstance(data, dict):
return None
mini_qrcode_image = data.get("mini_qrcode_image")
if isinstance(mini_qrcode_image, str) and mini_qrcode_image:
data["has_mini_qrcode"] = True
data.pop("mini_qrcode_image", None)
elif data.get("has_mini_qrcode"):
data["has_mini_qrcode"] = True
removable_keys = {
"bind_info",
"before_bind_info",