From 4a87a57a65683af43772570cee5f4abad809e8d8 Mon Sep 17 00:00:00 2001 From: Roger Far Date: Wed, 9 Jun 2021 18:59:06 -0600 Subject: [PATCH] Fixed retrying failed selecting of torrent files. --- server/RdtClient.Service/Services/Torrents.cs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 997718b..869b1d6 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -184,16 +184,35 @@ namespace RdtClient.Service.Services { var torrent = await GetById(torrentId); - await GetRdNetClient().SelectTorrentFilesAsync(torrent.RdId, fileIds.ToArray()); + RDNET.Torrent rdTorrent = null; - var rdTorrent = await GetRdNetClient().GetTorrentInfoAsync(torrent.RdId); + for (var i = 0; i < 5; i++) + { + await GetRdNetClient().SelectTorrentFilesAsync(torrent.RdId, fileIds.ToArray()); + + await Task.Delay(5000); + + rdTorrent = await GetRdNetClient().GetTorrentInfoAsync(torrent.RdId); + + if (fileIds.Count == rdTorrent.Links.Count) + { + break; + } + + await Task.Delay(10000); + } + + if (rdTorrent == null) + { + return; + } foreach (var file in rdTorrent.Links) { // Make sure downloads don't get added multiple times var downloadExists = await _downloads.Get(torrent.TorrentId, file); - if (downloadExists == null) + if (downloadExists == null && !String.IsNullOrWhiteSpace(file)) { await _downloads.Add(torrent.TorrentId, file); }