Request api racing fixes (#19)
* * added artist to lidarr/album.py payload to prevent lidarr error * added images: [] to lidarr/album.py payload to prevent lidarr NOT NULL constraint * moved _wait_for_artist_commands_to_complete() to before album is indexed to avoid race * removed check for releases in album_is_indexed as not all albums return from lidarr with releases * focused in error message on metadata profile exclusions to give more accurate error messaging * increased poll time for album_is_indexed to 5 seconds to reduce load on lidarr * added handling for when cmd_artist_ids is a single int instead of a list * * replaced original `_wait_for_artist_commands_to_complete` and moved earlier call into `if not album_obj` * replaced original clean Metadata Profile error messaging and added `logger.debug()` for raw error message from Lidarr
This commit is contained in:
@@ -298,9 +298,10 @@ class LidarrAlbumRepository(LidarrHistoryRepository):
|
|||||||
if not album_obj:
|
if not album_obj:
|
||||||
async def album_is_indexed():
|
async def album_is_indexed():
|
||||||
a = await self._get_album_by_foreign_id(musicbrainz_id)
|
a = await self._get_album_by_foreign_id(musicbrainz_id)
|
||||||
return a and a.get("id") and a.get("releases")
|
return a and a.get("id")
|
||||||
|
|
||||||
album_obj = await self._wait_for(album_is_indexed, timeout=60.0, poll=3.0)
|
await self._wait_for_artist_commands_to_complete(artist_id, timeout=600.0)
|
||||||
|
album_obj = await self._wait_for(album_is_indexed, timeout=60.0, poll=5.0)
|
||||||
|
|
||||||
if not album_obj:
|
if not album_obj:
|
||||||
profile_id = artist.get("qualityProfileId")
|
profile_id = artist.get("qualityProfileId")
|
||||||
@@ -316,10 +317,12 @@ class LidarrAlbumRepository(LidarrHistoryRepository):
|
|||||||
payload = {
|
payload = {
|
||||||
"title": album_title,
|
"title": album_title,
|
||||||
"artistId": artist_id,
|
"artistId": artist_id,
|
||||||
|
"artist": artist,
|
||||||
"foreignAlbumId": musicbrainz_id,
|
"foreignAlbumId": musicbrainz_id,
|
||||||
"monitored": True,
|
"monitored": True,
|
||||||
"anyReleaseOk": True,
|
"anyReleaseOk": True,
|
||||||
"profileId": profile_id,
|
"profileId": profile_id,
|
||||||
|
"images": [],
|
||||||
"addOptions": {"addType": "automatic", "searchForNewAlbum": True},
|
"addOptions": {"addType": "automatic", "searchForNewAlbum": True},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +331,9 @@ class LidarrAlbumRepository(LidarrHistoryRepository):
|
|||||||
action = "added"
|
action = "added"
|
||||||
album_obj = await self._wait_for(album_is_indexed, timeout=120.0, poll=2.0)
|
album_obj = await self._wait_for(album_is_indexed, timeout=120.0, poll=2.0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "POST failed" in str(e) or "405" in str(e):
|
err_str = str(e)
|
||||||
|
if "POST failed" in err_str or "405" in err_str:
|
||||||
|
logger.debug("Raw Lidarr rejection for %s: %s", album_title, err_str)
|
||||||
raise ExternalServiceError(
|
raise ExternalServiceError(
|
||||||
f"Cannot add this {album_type}. "
|
f"Cannot add this {album_type}. "
|
||||||
f"Lidarr rejected adding '{album_title}'. This is likely because your Lidarr "
|
f"Lidarr rejected adding '{album_title}'. This is likely because your Lidarr "
|
||||||
@@ -337,6 +342,7 @@ class LidarrAlbumRepository(LidarrHistoryRepository):
|
|||||||
f"and enable '{album_type}' in your active profile."
|
f"and enable '{album_type}' in your active profile."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
logger.debug("Unexpected error adding '%s': %s", album_title, err_str)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if not album_obj or "id" not in album_obj:
|
if not album_obj or "id" not in album_obj:
|
||||||
@@ -397,6 +403,9 @@ class LidarrAlbumRepository(LidarrHistoryRepository):
|
|||||||
cmd_artist_id = body.get("artistId")
|
cmd_artist_id = body.get("artistId")
|
||||||
cmd_artist_ids = body.get("artistIds", [])
|
cmd_artist_ids = body.get("artistIds", [])
|
||||||
|
|
||||||
|
if not isinstance(cmd_artist_ids, list):
|
||||||
|
cmd_artist_ids = [cmd_artist_ids] if cmd_artist_ids else []
|
||||||
|
|
||||||
if cmd_artist_id == artist_id or artist_id in cmd_artist_ids:
|
if cmd_artist_id == artist_id or artist_id in cmd_artist_ids:
|
||||||
has_running_commands = True
|
has_running_commands = True
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user