Skip to content

Commit

Permalink
change: change logic in qbdownloader class.
Browse files Browse the repository at this point in the history
  • Loading branch information
EstrellaXD committed Oct 15, 2023
1 parent a1f2dc9 commit 67a1949
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions backend/src/module/downloader/client/qb_downloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging
import httpx
import asyncio

from ..exceptions import ConflictError, AuthorizationError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions backend/src/module/downloader/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
class ConflictError(Exception):
pass


class AuthorizationError(Exception):
pass

0 comments on commit 67a1949

Please sign in to comment.