fix 重连机制
This commit is contained in:
@ -28,7 +28,7 @@ class EmbyModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.emby.user:
|
if not self.emby.is_inactive():
|
||||||
self.emby = Emby()
|
self.emby = Emby()
|
||||||
|
|
||||||
def user_authenticate(self, name: str, password: str) -> Optional[str]:
|
def user_authenticate(self, name: str, password: str) -> Optional[str]:
|
||||||
|
@ -27,6 +27,14 @@ class Emby(metaclass=Singleton):
|
|||||||
self.user = self.get_user()
|
self.user = self.get_user()
|
||||||
self.folders = self.get_emby_folders()
|
self.folders = self.get_emby_folders()
|
||||||
|
|
||||||
|
def is_inactive(self) -> bool:
|
||||||
|
"""
|
||||||
|
判断是否需要重连
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return False
|
||||||
|
return True if not self.user else False
|
||||||
|
|
||||||
def get_emby_folders(self) -> List[dict]:
|
def get_emby_folders(self) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取Emby媒体库路径列表
|
获取Emby媒体库路径列表
|
||||||
|
@ -25,7 +25,7 @@ class JellyfinModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.jellyfin.user:
|
if not self.jellyfin.is_inactive():
|
||||||
self.jellyfin = Jellyfin()
|
self.jellyfin = Jellyfin()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@ -25,6 +25,14 @@ class Jellyfin(metaclass=Singleton):
|
|||||||
self.user = self.get_user()
|
self.user = self.get_user()
|
||||||
self.serverid = self.get_server_id()
|
self.serverid = self.get_server_id()
|
||||||
|
|
||||||
|
def is_inactive(self) -> bool:
|
||||||
|
"""
|
||||||
|
判断是否需要重连
|
||||||
|
"""
|
||||||
|
if not self._host or not self._apikey:
|
||||||
|
return False
|
||||||
|
return True if not self.user else False
|
||||||
|
|
||||||
def __get_jellyfin_librarys(self) -> List[dict]:
|
def __get_jellyfin_librarys(self) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
获取Jellyfin媒体库的信息
|
获取Jellyfin媒体库的信息
|
||||||
|
@ -28,7 +28,7 @@ class PlexModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.plex.get_plex():
|
if not self.plex.is_inactive():
|
||||||
self.plex = Plex()
|
self.plex = Plex()
|
||||||
|
|
||||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> WebhookEventInfo:
|
def webhook_parser(self, body: Any, form: Any, args: Any) -> WebhookEventInfo:
|
||||||
|
@ -30,6 +30,14 @@ class Plex(metaclass=Singleton):
|
|||||||
self._plex = None
|
self._plex = None
|
||||||
logger.error(f"Plex服务器连接失败:{str(e)}")
|
logger.error(f"Plex服务器连接失败:{str(e)}")
|
||||||
|
|
||||||
|
def is_inactive(self) -> bool:
|
||||||
|
"""
|
||||||
|
判断是否需要重连
|
||||||
|
"""
|
||||||
|
if not self._host or not self._token:
|
||||||
|
return False
|
||||||
|
return True if not self._plex else False
|
||||||
|
|
||||||
def get_librarys(self):
|
def get_librarys(self):
|
||||||
"""
|
"""
|
||||||
获取媒体服务器所有媒体库列表
|
获取媒体服务器所有媒体库列表
|
||||||
|
@ -33,7 +33,7 @@ class QbittorrentModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.qbittorrent.qbc:
|
if self.qbittorrent.is_inactive():
|
||||||
self.qbittorrent = Qbittorrent()
|
self.qbittorrent = Qbittorrent()
|
||||||
|
|
||||||
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
|
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
|
||||||
|
@ -27,6 +27,14 @@ class Qbittorrent(metaclass=Singleton):
|
|||||||
if self._host and self._port:
|
if self._host and self._port:
|
||||||
self.qbc = self.__login_qbittorrent()
|
self.qbc = self.__login_qbittorrent()
|
||||||
|
|
||||||
|
def is_inactive(self) -> bool:
|
||||||
|
"""
|
||||||
|
判断是否需要重连
|
||||||
|
"""
|
||||||
|
if not self._host or not self._port:
|
||||||
|
return False
|
||||||
|
return True if not self.qbc else False
|
||||||
|
|
||||||
def __login_qbittorrent(self) -> Optional[Client]:
|
def __login_qbittorrent(self) -> Optional[Client]:
|
||||||
"""
|
"""
|
||||||
连接qbittorrent
|
连接qbittorrent
|
||||||
|
@ -33,7 +33,7 @@ class TransmissionModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
# 定时重连
|
# 定时重连
|
||||||
if not self.transmission.trc:
|
if not self.transmission.is_inactive():
|
||||||
self.transmission = Transmission()
|
self.transmission = Transmission()
|
||||||
|
|
||||||
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
|
def download(self, torrent_path: Path, download_dir: Path, cookie: str,
|
||||||
|
@ -28,7 +28,7 @@ class Transmission(metaclass=Singleton):
|
|||||||
self._host, self._port = StringUtils.get_domain_address(address=settings.TR_HOST, prefix=False)
|
self._host, self._port = StringUtils.get_domain_address(address=settings.TR_HOST, prefix=False)
|
||||||
self._username = settings.TR_USER
|
self._username = settings.TR_USER
|
||||||
self._password = settings.TR_PASSWORD
|
self._password = settings.TR_PASSWORD
|
||||||
if self._host and self._port and self._username and self._password:
|
if self._host and self._port:
|
||||||
self.trc = self.__login_transmission()
|
self.trc = self.__login_transmission()
|
||||||
|
|
||||||
def __login_transmission(self) -> Optional[Client]:
|
def __login_transmission(self) -> Optional[Client]:
|
||||||
@ -48,6 +48,14 @@ class Transmission(metaclass=Singleton):
|
|||||||
logger.error(f"transmission 连接出错:{err}")
|
logger.error(f"transmission 连接出错:{err}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def is_inactive(self) -> bool:
|
||||||
|
"""
|
||||||
|
判断是否需要重连
|
||||||
|
"""
|
||||||
|
if not self._host or not self._port:
|
||||||
|
return False
|
||||||
|
return True if not self.trc else False
|
||||||
|
|
||||||
def get_torrents(self, ids: Union[str, list] = None, status: Union[str, list] = None,
|
def get_torrents(self, ids: Union[str, list] = None, status: Union[str, list] = None,
|
||||||
tags: Union[str, list] = None) -> Tuple[List[Torrent], bool]:
|
tags: Union[str, list] = None) -> Tuple[List[Torrent], bool]:
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user