refactor:Module加入执行优先顺序

This commit is contained in:
jxxghp
2024-10-19 19:31:25 +08:00
parent de17bc5645
commit 363f12ed5a
22 changed files with 150 additions and 0 deletions

View File

@@ -96,6 +96,8 @@ class ChainBase(metaclass=ABCMeta):
logger.debug(f"请求模块执行:{method} ...")
result = None
modules = self.modulemanager.get_running_modules(method)
# 按优先级排序
modules = sorted(modules, key=lambda x: x.get_priority())
for module in modules:
module_id = module.__class__.__name__
try:

View File

@@ -42,6 +42,14 @@ class _ModuleBase(metaclass=ABCMeta):
获取模块类型
"""
pass
@staticmethod
@abstractmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
pass
@abstractmethod
def stop(self) -> None:

View File

@@ -44,6 +44,13 @@ class BangumiModule(_ModuleBase):
获取模块类型
"""
return ModuleType.MediaRecognize
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 3
def recognize_media(self, bangumiid: int = None,
**kwargs) -> Optional[MediaInfo]:

View File

@@ -58,6 +58,13 @@ class DoubanModule(_ModuleBase):
"""
return ModuleType.MediaRecognize
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 2
def recognize_media(self, meta: MetaBase = None,
mtype: MediaType = None,
doubanid: str = None,

View File

@@ -29,6 +29,13 @@ class EmbyModule(_ModuleBase, _MediaServerBase[Emby]):
"""
return ModuleType.MediaServer
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 1
def stop(self):
pass

View File

@@ -342,6 +342,13 @@ class FanartModule(_ModuleBase):
"""
return ModuleType.Other
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 0
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
"""
获取图片

View File

@@ -51,6 +51,13 @@ class FileManagerModule(_ModuleBase):
"""
return ModuleType.Other
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 4
def stop(self):
pass

View File

@@ -167,6 +167,13 @@ class FilterModule(_ModuleBase):
"""
return ModuleType.Other
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 4
def stop(self):
pass

View File

@@ -47,6 +47,13 @@ class IndexerModule(_ModuleBase):
"""
return ModuleType.Indexer
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 0
def stop(self):
pass

View File

@@ -29,6 +29,13 @@ class JellyfinModule(_ModuleBase, _MediaServerBase[Jellyfin]):
"""
return ModuleType.MediaServer
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 2
def init_setting(self) -> Tuple[str, Union[str, bool]]:
pass

View File

@@ -28,6 +28,13 @@ class PlexModule(_ModuleBase, _MediaServerBase[Plex]):
"""
return ModuleType.MediaServer
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 3
def stop(self):
pass

View File

@@ -37,6 +37,13 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]):
"""
return ModuleType.Downloader
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 1
def stop(self):
pass

View File

@@ -31,6 +31,13 @@ class SlackModule(_ModuleBase, _MessageBase[Slack]):
"""
return ModuleType.Notification
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 3
def stop(self):
"""
停止模块

View File

@@ -40,6 +40,13 @@ class SubtitleModule(_ModuleBase):
"""
return ModuleType.Other
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 0
def init_setting(self) -> Tuple[str, Union[str, bool]]:
pass

View File

@@ -29,6 +29,13 @@ class SynologyChatModule(_ModuleBase, _MessageBase[SynologyChat]):
"""
return ModuleType.Notification
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 5
def stop(self):
pass

View File

@@ -30,6 +30,13 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
"""
return ModuleType.Notification
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 0
def stop(self):
"""
停止模块

View File

@@ -48,6 +48,13 @@ class TheMovieDbModule(_ModuleBase):
"""
return ModuleType.MediaRecognize
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 1
def stop(self):
self.cache.save()
self.tmdb.close()

View File

@@ -28,6 +28,13 @@ class TheTvDbModule(_ModuleBase):
"""
return ModuleType.MediaRecognize
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 4
def stop(self):
self.tvdb.close()

View File

@@ -37,6 +37,13 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]):
"""
return ModuleType.Downloader
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 2
def stop(self):
pass

View File

@@ -30,6 +30,13 @@ class VoceChatModule(_ModuleBase, _MessageBase[VoceChat]):
"""
return ModuleType.Notification
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 4
def stop(self):
pass

View File

@@ -30,6 +30,13 @@ class WebPushModule(_ModuleBase, _MessageBase):
"""
return ModuleType.Notification
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 6
def stop(self):
pass

View File

@@ -32,6 +32,13 @@ class WechatModule(_ModuleBase, _MessageBase[WeChat]):
"""
return ModuleType.Notification
@staticmethod
def get_priority() -> int:
"""
获取模块优先级,数字越小优先级越高,只有同一接口下优先级才生效
"""
return 1
def stop(self):
pass