Fixed simple downloader retrying.

This commit is contained in:
Roger Far 2021-10-28 17:15:47 -06:00
parent 0d5d28483b
commit 075f494ec6
3 changed files with 15 additions and 5 deletions

View file

@ -63,7 +63,7 @@ namespace RdtClient.Service.Services
Downloader.DownloadComplete += (_, args) => Downloader.DownloadComplete += (_, args) =>
{ {
Finished = true; Finished = true;
Error = args.Error; Error ??= args.Error;
}; };
Downloader.DownloadProgress += (_, args) => Downloader.DownloadProgress += (_, args) =>
@ -81,6 +81,11 @@ namespace RdtClient.Service.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Downloader != null)
{
await Downloader.Cancel();
}
Error = $"An unexpected error occurred preparing download {_download.Link} for torrent {_torrent.RdName}: {ex.Message}"; Error = $"An unexpected error occurred preparing download {_download.Link} for torrent {_torrent.RdName}: {ex.Message}";
Finished = true; Finished = true;

View file

@ -42,7 +42,7 @@ namespace RdtClient.Service.Services.Downloaders
await StartDownloadTask(); await StartDownloadTask();
}); });
return null; return Task.FromResult<String>(null);
} }
public Task Cancel() public Task Cancel()
@ -137,6 +137,11 @@ namespace RdtClient.Service.Services.Downloaders
} }
} }
if (_cancelled)
{
throw new Exception("Download cancelled");
}
if (timeout <= DateTimeOffset.UtcNow) if (timeout <= DateTimeOffset.UtcNow)
{ {
throw new Exception($"Download timed out"); throw new Exception($"Download timed out");

View file

@ -184,8 +184,8 @@ namespace RdtClient.Service.Services
{ {
Log($"Retrying download", download, download.Torrent); Log($"Retrying download", download, download.Torrent);
await _downloads.UpdateRetryCount(downloadId, download.RetryCount + 1);
await _downloads.Reset(downloadId); await _downloads.Reset(downloadId);
await _downloads.UpdateRetryCount(downloadId, download.RetryCount + 1);
} }
else if (download.Torrent.RetryCount < TorrentRetryCount) else if (download.Torrent.RetryCount < TorrentRetryCount)
{ {