Improve stalled and failed imports (#37)

This commit is contained in:
Marius Nechifor
2025-01-13 13:18:58 +02:00
committed by GitHub
parent c7ad1c5ee6
commit f0dc51f10b
20 changed files with 204 additions and 38 deletions
@@ -38,17 +38,19 @@ public sealed class TransmissionService : DownloadServiceBase
await _client.GetSessionInformationAsync();
}
public override async Task<bool> ShouldRemoveFromArrQueueAsync(string hash)
public override async Task<RemoveResult> ShouldRemoveFromArrQueueAsync(string hash)
{
RemoveResult result = new();
TorrentInfo? torrent = await GetTorrentAsync(hash);
if (torrent is null)
{
_logger.LogDebug("failed to find torrent {hash} in the download client", hash);
return false;
return result;
}
bool shouldRemove = torrent.FileStats?.Length > 0;
result.IsPrivate = torrent.IsPrivate ?? false;
foreach (TransmissionTorrentFileStats? stats in torrent.FileStats ?? [])
{
@@ -65,8 +67,10 @@ public sealed class TransmissionService : DownloadServiceBase
}
}
// remove if all files are unwanted
return shouldRemove || IsItemStuckAndShouldRemove(torrent);
// remove if all files are unwanted or download is stuck
result.ShouldRemove = shouldRemove || IsItemStuckAndShouldRemove(torrent);
return result;
}
public override async Task BlockUnwantedFilesAsync(string hash)
@@ -116,6 +120,18 @@ public sealed class TransmissionService : DownloadServiceBase
private bool IsItemStuckAndShouldRemove(TorrentInfo torrent)
{
if (_queueCleanerConfig.StalledMaxStrikes is 0)
{
return false;
}
if (_queueCleanerConfig.StalledIgnorePrivate && (torrent.IsPrivate ?? false))
{
// ignore private trackers
_logger.LogDebug("skip stalled check | download is private | {name}", torrent.Name);
return false;
}
if (torrent.Status is not 4)
{
// not in downloading state
@@ -144,7 +160,8 @@ public sealed class TransmissionService : DownloadServiceBase
TorrentFields.ID,
TorrentFields.ETA,
TorrentFields.NAME,
TorrentFields.STATUS
TorrentFields.STATUS,
TorrentFields.IS_PRIVATE
];
// refresh cache