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) =>
{
Finished = true;
Error = args.Error;
Error ??= args.Error;
};
Downloader.DownloadProgress += (_, args) =>
@ -74,13 +74,18 @@ namespace RdtClient.Service.Services
};
var result = await Downloader.Download();
await Task.Delay(1000);
return result;
}
catch (Exception ex)
{
if (Downloader != null)
{
await Downloader.Cancel();
}
Error = $"An unexpected error occurred preparing download {_download.Link} for torrent {_torrent.RdName}: {ex.Message}";
Finished = true;

View file

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

View file

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