diff --git a/backend/src/module/downloader/client/qb_downloader.py b/backend/src/module/downloader/client/qb_downloader.py index ed7b0a131..789c7a6c5 100644 --- a/backend/src/module/downloader/client/qb_downloader.py +++ b/backend/src/module/downloader/client/qb_downloader.py @@ -1,5 +1,8 @@ import logging import httpx +import asyncio + +from ..exceptions import ConflictError, AuthorizationError logger = logging.getLogger(__name__) @@ -131,6 +134,12 @@ async def __aenter__(self): self._client = httpx.AsyncClient( base_url=self.host, ) + while not await self.check_host(): + logger.warning(f"[Downloader] Failed to connect to {self.host}, retry in 30 seconds.") + await asyncio.sleep(30) + if not await self.auth(): + await self._client.aclose() + raise AuthorizationError("Failed to login to qbittorrent.") return self async def __aexit__(self, exc_type, exc_val, exc_tb): diff --git a/backend/src/module/downloader/exceptions.py b/backend/src/module/downloader/exceptions.py index 7ec28c73a..4fcc3142a 100644 --- a/backend/src/module/downloader/exceptions.py +++ b/backend/src/module/downloader/exceptions.py @@ -1,2 +1,7 @@ class ConflictError(Exception): pass + + +class AuthorizationError(Exception): + pass +