mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-07-05 03:27:57 +08:00
fix(downloader): add retry logic for transient network errors in add_torrents
Handles httpx.ReadError and other network exceptions when adding torrents to qBittorrent by retrying up to 3 times with a 2-second delay. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -135,12 +135,24 @@ class QbDownloader:
|
||||
else:
|
||||
files["torrents"] = ("torrent.torrent", torrent_files, "application/x-bittorrent")
|
||||
|
||||
resp = await self._client.post(
|
||||
self._url("torrents/add"),
|
||||
data=data,
|
||||
files=files if files else None,
|
||||
)
|
||||
return resp.text == "Ok."
|
||||
max_retries = 3
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
resp = await self._client.post(
|
||||
self._url("torrents/add"),
|
||||
data=data,
|
||||
files=files if files else None,
|
||||
)
|
||||
return resp.text == "Ok."
|
||||
except (httpx.ReadError, httpx.ConnectError, httpx.RequestError) as e:
|
||||
if attempt < max_retries - 1:
|
||||
logger.warning(
|
||||
f"[Downloader] Network error adding torrent (attempt {attempt + 1}/{max_retries}): {e}"
|
||||
)
|
||||
await asyncio.sleep(2)
|
||||
else:
|
||||
logger.error(f"[Downloader] Failed to add torrent after {max_retries} attempts: {e}")
|
||||
raise
|
||||
|
||||
async def torrents_delete(self, hash, delete_files: bool = True):
|
||||
await self._client.post(
|
||||
|
||||
Reference in New Issue
Block a user