mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 08:26:53 +08:00
fix: await durable subscribe deletion reports
This commit is contained in:
Vendored
+20
@@ -662,6 +662,15 @@ class MoviePilotServerHelper:
|
||||
"""
|
||||
return cls._post_json(cls._server_url(cls._SUBSCRIBE_DONE_PATH), payload, timeout=5)
|
||||
|
||||
@classmethod
|
||||
async def async_subscribe_done(cls, payload: Dict[str, Any]):
|
||||
"""异步完成订阅统计,并返回可检查 HTTP 状态的响应对象。"""
|
||||
return await cls._async_post_json(
|
||||
cls._server_url(cls._SUBSCRIBE_DONE_PATH),
|
||||
payload,
|
||||
timeout=5,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def subscribe_report(cls, subscribes: List[Dict[str, Any]]):
|
||||
"""
|
||||
@@ -874,6 +883,17 @@ class MoviePilotServerHelper:
|
||||
res = cls.subscribe_done(payload)
|
||||
return bool(res is not None and res.status_code == 200)
|
||||
|
||||
@classmethod
|
||||
async def async_sub_done(cls, sub: dict) -> bool:
|
||||
"""异步完成订阅统计,并仅在服务端确认成功时返回 True。"""
|
||||
if not settings.SUBSCRIBE_STATISTIC_SHARE:
|
||||
return False
|
||||
payload = cls._build_subscribe_statistic_payload(sub)
|
||||
if not payload:
|
||||
return False
|
||||
res = await cls.async_subscribe_done(payload)
|
||||
return bool(res is not None and res.status_code == 200)
|
||||
|
||||
@classmethod
|
||||
def sub_reg_async(cls, sub: dict) -> bool:
|
||||
"""
|
||||
|
||||
@@ -62,7 +62,7 @@ def get_delete_subscribe_command(
|
||||
repository=cast(SubscribeDeletionRepository, repository_port),
|
||||
unit_of_work=cast(DeleteUnitOfWork, unit_of_work),
|
||||
publish_deleted=_publish_subscribe_deleted,
|
||||
report_deleted=MoviePilotServerHelper.sub_done_async,
|
||||
report_deleted=MoviePilotServerHelper.async_sub_done,
|
||||
outbox=outbox,
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from contextlib import AbstractAsyncContextManager
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
import inspect
|
||||
from typing import Any, Awaitable, Callable, Mapping, Protocol, cast
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -55,7 +56,7 @@ class AsyncUnitOfWork(Protocol):
|
||||
|
||||
|
||||
SubscribeDeletedPublisher = Callable[[dict[str, Any]], Awaitable[None]]
|
||||
SubscribeDeletedReporter = Callable[[Mapping[str, object]], object]
|
||||
SubscribeDeletedReporter = Callable[[Mapping[str, object]], object | Awaitable[object]]
|
||||
|
||||
|
||||
class DeleteSubscribeCommand:
|
||||
@@ -134,6 +135,8 @@ class DeleteSubscribeCommand:
|
||||
# 上报适配器会自行白名单过滤公开字段;传完整删除前快照可保留音乐实体维度,
|
||||
# 避免 Agent 与 API 入口收敛后丢失 music_type / total_tracks。
|
||||
report_result = self._report_deleted(dict(candidate.event_payload))
|
||||
if inspect.isawaitable(report_result):
|
||||
report_result = await report_result
|
||||
if report_result is False:
|
||||
raise RuntimeError("订阅删除统计上报未确认")
|
||||
if self._outbox:
|
||||
|
||||
@@ -145,7 +145,7 @@ async def delete_subscribe_scope():
|
||||
repository=SubscribeOper(session),
|
||||
unit_of_work=SqlAlchemyAsyncUnitOfWork(session),
|
||||
publish_deleted=_publish_deleted,
|
||||
report_deleted=MoviePilotServerHelper.sub_done_async,
|
||||
report_deleted=MoviePilotServerHelper.async_sub_done,
|
||||
outbox=SqlAlchemyAsyncOutboxStager(session),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user