Finished torrent retry.

This commit is contained in:
Roger Far 2021-10-11 14:06:57 -06:00
parent 399456c815
commit ae41865bb2
5 changed files with 50 additions and 36 deletions

View file

@ -15,4 +15,5 @@ export class Download {
public bytesTotal: number; public bytesTotal: number;
public bytesDone: number; public bytesDone: number;
public speed: number; public speed: number;
public retryCount: number;
} }

View file

@ -16,6 +16,8 @@ export class Torrent {
public fileOrMagnet: string; public fileOrMagnet: string;
public isFile: boolean; public isFile: boolean;
public retryCount: number;
public rdId: string; public rdId: string;
public rdName: string; public rdName: string;
public rdSize: number; public rdSize: number;

View file

@ -32,6 +32,10 @@
<label class="label">Status</label> <label class="label">Status</label>
{{ torrent | status }} {{ torrent | status }}
</div> </div>
<div class="field">
<label class="label">Retry count</label>
{{ torrent.retryCount }} / 2
</div>
<div class="field"> <div class="field">
<label class="label">Hash</label> <label class="label">Hash</label>
{{ torrent.hash }} {{ torrent.hash }}
@ -245,7 +249,7 @@
</div> </div>
<div class="field"> <div class="field">
<label class="label">Retry Count</label> <label class="label">Retry Count</label>
{{ download.retryCount }} {{ download.retryCount }} / 3
</div> </div>
</div> </div>
<div fxFlex> <div fxFlex>

View file

@ -115,7 +115,10 @@ namespace RdtClient.Service.Services
{ {
Log.Debug($"Processing active download {downloadId}: error {downloadClient.Error}, download retry count {download.RetryCount}/{DownloadRetryCount}, torrent retry count {download.Torrent.RetryCount}/{TorrentRetryCount}, retrying torrent"); Log.Debug($"Processing active download {downloadId}: error {downloadClient.Error}, download retry count {download.RetryCount}/{DownloadRetryCount}, torrent retry count {download.Torrent.RetryCount}/{TorrentRetryCount}, retrying torrent");
Task.Run(async () =>
{
await _torrents.RetryTorrent(download.TorrentId); await _torrents.RetryTorrent(download.TorrentId);
});
} }
else else
{ {

View file

@ -101,7 +101,7 @@ namespace RdtClient.Service.Services
await _torrentData.UpdateCategory(torrent.TorrentId, category); await _torrentData.UpdateCategory(torrent.TorrentId, category);
} }
public async Task UploadMagnet(String magnetLink, public async Task<Torrent> UploadMagnet(String magnetLink,
String category, String category,
TorrentDownloadAction downloadAction, TorrentDownloadAction downloadAction,
TorrentFinishedAction finishedAction, TorrentFinishedAction finishedAction,
@ -121,10 +121,10 @@ namespace RdtClient.Service.Services
var rdTorrent = await GetRdNetClient().Torrents.AddMagnetAsync(magnetLink); var rdTorrent = await GetRdNetClient().Torrents.AddMagnetAsync(magnetLink);
await Add(rdTorrent.Id, magnet.InfoHash.ToHex(), category, downloadAction, finishedAction, downloadMinSize, downloadManualFiles, magnetLink, false); return await Add(rdTorrent.Id, magnet.InfoHash.ToHex(), category, downloadAction, finishedAction, downloadMinSize, downloadManualFiles, magnetLink, false);
} }
public async Task UploadFile(Byte[] bytes, public async Task<Torrent> UploadFile(Byte[] bytes,
String category, String category,
TorrentDownloadAction downloadAction, TorrentDownloadAction downloadAction,
TorrentFinishedAction finishedAction, TorrentFinishedAction finishedAction,
@ -146,7 +146,7 @@ namespace RdtClient.Service.Services
var rdTorrent = await GetRdNetClient().Torrents.AddFileAsync(bytes); var rdTorrent = await GetRdNetClient().Torrents.AddFileAsync(bytes);
await Add(rdTorrent.Id, torrent.InfoHash.ToHex(), category, downloadAction, finishedAction, downloadMinSize, downloadManualFiles, fileAsBase64, true); return await Add(rdTorrent.Id, torrent.InfoHash.ToHex(), category, downloadAction, finishedAction, downloadMinSize, downloadManualFiles, fileAsBase64, true);
} }
public async Task<List<TorrentInstantAvailabilityFile>> GetAvailableFiles(String hash) public async Task<List<TorrentInstantAvailabilityFile>> GetAvailableFiles(String hash)
@ -394,14 +394,14 @@ namespace RdtClient.Service.Services
{ {
downloadClient.Cancel(); downloadClient.Cancel();
await Task.Delay(1000); await Task.Delay(100);
} }
while (TorrentRunner.ActiveUnpackClients.TryGetValue(download.DownloadId, out var unpackClient)) while (TorrentRunner.ActiveUnpackClients.TryGetValue(download.DownloadId, out var unpackClient))
{ {
unpackClient.Cancel(); unpackClient.Cancel();
await Task.Delay(1000); await Task.Delay(100);
} }
} }
@ -416,15 +416,17 @@ namespace RdtClient.Service.Services
try try
{ {
Torrent newTorrent;
if (torrent.IsFile) if (torrent.IsFile)
{ {
var bytes = Convert.FromBase64String(torrent.FileOrMagnet); var bytes = Convert.FromBase64String(torrent.FileOrMagnet);
await UploadFile(bytes, torrent.Category, torrent.DownloadAction, torrent.FinishedAction, torrent.DownloadMinSize, torrent.DownloadManualFiles); newTorrent = await UploadFile(bytes, torrent.Category, torrent.DownloadAction, torrent.FinishedAction, torrent.DownloadMinSize, torrent.DownloadManualFiles);
} }
else else
{ {
await UploadMagnet(torrent.FileOrMagnet, newTorrent = await UploadMagnet(torrent.FileOrMagnet,
torrent.Category, torrent.Category,
torrent.DownloadAction, torrent.DownloadAction,
torrent.FinishedAction, torrent.FinishedAction,
@ -432,7 +434,7 @@ namespace RdtClient.Service.Services
torrent.DownloadManualFiles); torrent.DownloadManualFiles);
} }
await _torrentData.UpdateRetryCount(torrent.TorrentId, newRetryCount); await _torrentData.UpdateRetryCount(newTorrent.TorrentId, newRetryCount);
} }
finally finally
{ {
@ -530,7 +532,7 @@ namespace RdtClient.Service.Services
return settingDownloadPath; return settingDownloadPath;
} }
private async Task Add(String rdTorrentId, private async Task<Torrent> Add(String rdTorrentId,
String infoHash, String infoHash,
String category, String category,
TorrentDownloadAction downloadAction, TorrentDownloadAction downloadAction,
@ -548,7 +550,7 @@ namespace RdtClient.Service.Services
if (torrent != null) if (torrent != null)
{ {
return; return torrent;
} }
var newTorrent = await _torrentData.Add(rdTorrentId, var newTorrent = await _torrentData.Add(rdTorrentId,
@ -562,6 +564,8 @@ namespace RdtClient.Service.Services
isFile); isFile);
await Update(newTorrent); await Update(newTorrent);
return newTorrent;
} }
finally finally
{ {