diff --git a/server/RdtClient.Data/Data/TorrentData.cs b/server/RdtClient.Data/Data/TorrentData.cs index 650a723..bed2ea1 100644 --- a/server/RdtClient.Data/Data/TorrentData.cs +++ b/server/RdtClient.Data/Data/TorrentData.cs @@ -177,7 +177,7 @@ namespace RdtClient.Data.Data await VoidCache(); } - public async Task UpdateComplete(Guid torrentId, String error, DateTimeOffset? datetime) + public async Task UpdateComplete(Guid torrentId, String error, DateTimeOffset? datetime, Boolean retry) { var dbTorrent = await _dataContext.Torrents.FirstOrDefaultAsync(m => m.TorrentId == torrentId); @@ -191,13 +191,13 @@ namespace RdtClient.Data.Data var downloads = await _dataContext.Downloads.AsNoTracking().Where(m => m.TorrentId == torrentId).ToListAsync(); var downloadWithErrors = downloads.Where(m => !String.IsNullOrWhiteSpace(m.Error)).ToList(); - if (downloads.Any()) + if (downloadWithErrors.Any()) { error = $"{downloadWithErrors.Count}/{downloads.Count} downloads failed with errors"; } } - if (!String.IsNullOrWhiteSpace(error)) + if (!String.IsNullOrWhiteSpace(error) && retry) { if (dbTorrent.RetryCount < dbTorrent.TorrentRetryAttempts) { diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 9090ef7..fb41a06 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -480,7 +480,7 @@ namespace RdtClient.Service.Services Log($"Received RealDebrid error: {torrent.RdStatusRaw}, not processing further", torrent); - await _torrents.UpdateComplete(torrent.TorrentId, $"Received RealDebrid error: {torrent.RdStatusRaw}.", DateTimeOffset.UtcNow); + await _torrents.UpdateComplete(torrent.TorrentId, $"Received RealDebrid error: {torrent.RdStatusRaw}.", DateTimeOffset.UtcNow, true); continue; } @@ -567,7 +567,7 @@ namespace RdtClient.Service.Services { Log($"All downloads complete, marking torrent as complete", torrent); - await _torrents.UpdateComplete(torrent.TorrentId, null, DateTimeOffset.UtcNow); + await _torrents.UpdateComplete(torrent.TorrentId, null, DateTimeOffset.UtcNow, true); switch (torrent.FinishedAction) { @@ -600,7 +600,7 @@ namespace RdtClient.Service.Services catch (Exception ex) { _logger.LogError(ex.Message, $"Torrent processing result in an unexpected exception: {ex.Message}"); - await _torrents.UpdateComplete(torrent.TorrentId, ex.Message, DateTimeOffset.UtcNow); + await _torrents.UpdateComplete(torrent.TorrentId, ex.Message, DateTimeOffset.UtcNow, true); } } diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 6463d2f..1adc1dd 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -209,7 +209,7 @@ namespace RdtClient.Service.Services Log($"Deleting", torrent); - await UpdateComplete(torrentId, "Torrent deleted", DateTimeOffset.UtcNow); + await UpdateComplete(torrentId, "Torrent deleted", DateTimeOffset.UtcNow, false); foreach (var download in torrent.Downloads) { @@ -374,7 +374,8 @@ namespace RdtClient.Service.Services Log($"Retrying Torrent", torrent); - await UpdateComplete(torrent.TorrentId, "Retrying Torrent", DateTimeOffset.UtcNow); + await UpdateComplete(torrent.TorrentId, "Retrying Torrent", DateTimeOffset.UtcNow, false); + await UpdateRetry(torrent.TorrentId, null, 0); foreach (var download in torrent.Downloads) { @@ -464,12 +465,12 @@ namespace RdtClient.Service.Services await _downloads.Reset(downloadId); - await _torrentData.UpdateComplete(download.TorrentId, null, null); + await _torrentData.UpdateComplete(download.TorrentId, null, null, false); } - public async Task UpdateComplete(Guid torrentId, String error, DateTimeOffset datetime) + public async Task UpdateComplete(Guid torrentId, String error, DateTimeOffset datetime, Boolean retry) { - await _torrentData.UpdateComplete(torrentId, error, datetime); + await _torrentData.UpdateComplete(torrentId, error, datetime, retry); } public async Task UpdateFilesSelected(Guid torrentId, DateTimeOffset datetime)