Improvement: Add error message to logs for failed imports (info-level)

This commit is contained in:
Benjamin Harder
2024-07-25 21:34:53 +02:00
parent d9c49693de
commit dd278b2b14
2 changed files with 29 additions and 7 deletions

View File

@@ -20,19 +20,31 @@ async def remove_failed_imports(settingsDict, BASE_URL, API_KEY, NAME, deleted_d
if queueItem['status'] == 'completed' \
and queueItem['trackedDownloadStatus'] == 'warning' \
and (queueItem['trackedDownloadState'] == 'importPending' or queueItem['trackedDownloadState'] == 'importFailed' or queueItem['trackedDownloadState'] == 'importBlocked'):
and queueItem['trackedDownloadState'] in {'importPending', 'importFailed', 'importBlocked'}:
# Find messages that find specified pattern and put them into a "removal_message" that will be displayed in the logger when removing the affected item
removal_messages = ['Tracked Download State: ' + queueItem['trackedDownloadState']]
for statusMessage in queueItem['statusMessages']:
if not settingsDict['FAILED_IMPORT_MESSAGE_PATTERNS'] or any(any(pattern in message for pattern in settingsDict['FAILED_IMPORT_MESSAGE_PATTERNS']) for message in statusMessage.get('messages', [])):
affectedItems.append(queueItem)
if not settingsDict['FAILED_IMPORT_MESSAGE_PATTERNS']: # No patterns defined - including all status messages in the removal_messages
removal_messages.append ('Status Messages (All):')
removal_messages.extend(f"- {msg}" for msg in statusMessage.get('messages', []))
break
removal_messages.append ('Status Messages (matching specified patterns):')
messages = statusMessage.get('messages', [])
for message in messages:
if any(pattern in message for pattern in settingsDict['FAILED_IMPORT_MESSAGE_PATTERNS']):
removal_messages.append(f"- {message}")
queueItem['removal_messages'] = removal_messages
affectedItems.append(queueItem)
affectedItems = await execute_checks(settingsDict, affectedItems, failType, BASE_URL, API_KEY, NAME, deleted_downloads, defective_tracker, privateDowloadIDs, protectedDownloadIDs,
addToBlocklist = True,
doPrivateTrackerCheck = False,
doProtectedDownloadCheck = True,
doPermittedAttemptsCheck = False,
extraParameters = ['keepTorrentForPrivateTrackers']
extraParameters = {'keepTorrentForPrivateTrackers': True}
)
return len(affectedItems)
except Exception as error:

View File

@@ -78,9 +78,10 @@ async def execute_checks(settingsDict, affectedItems, failType, BASE_URL, API_KE
for affectedItem in affectedItems:
# Checks whether when removing the queue item from the *arr app the torrent should be kept
removeFromClient = True
if 'keepTorrentForPrivateTrackers' in extraParameters:
if extraParameters.get('keepTorrentForPrivateTrackers', False):
if settingsDict['IGNORE_PRIVATE_TRACKERS'] and affectedItem['downloadId'] in privateDowloadIDs:
removeFromClient = False
# Removes the queue item
await remove_download(settingsDict, BASE_URL, API_KEY, affectedItem, failType, addToBlocklist, deleted_downloads, removeFromClient)
# Exit Logs
@@ -133,10 +134,19 @@ async def remove_download(settingsDict, BASE_URL, API_KEY, affectedItem, failTyp
# Removes downloads and creates log entry
logger.debug('remove_download/deleted_downloads.dict IN: %s', str(deleted_downloads.dict))
if affectedItem['downloadId'] not in deleted_downloads.dict:
# "schizophrenic" removal:
# Yes, the failed imports are removed from the -arr apps (so the removal kicks still in)
# But in the torrent client they are kept
if removeFromClient:
logger.info('>>> Removing %s download: %s', failType, affectedItem['title'])
else:
logger.info('>>> Removing %s download (without removing torrent): %s', failType, affectedItem['title'])
logger.info('>>> Removing %s download (without removing from torrent client): %s', failType, affectedItem['title'])
# Print out detailed removal messages (if any were added in the jobs)
if removal_messages in affectedItem:
for removal_message in affectedItem.removal_messages:
logger.info(removal_message)
if not settingsDict['TEST_RUN']:
await rest_delete(f'{BASE_URL}/queue/{affectedItem["id"]}', API_KEY, {'removeFromClient': removeFromClient, 'blocklist': addToBlocklist})
deleted_downloads.dict.append(affectedItem['downloadId'])