mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
rTorrent: Fixed race condition
This commit is contained in:
parent
db5494e7ac
commit
95017884d7
@ -40,23 +40,9 @@ protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string
|
|||||||
{
|
{
|
||||||
_proxy.AddTorrentFromUrl(magnetLink, Settings);
|
_proxy.AddTorrentFromUrl(magnetLink, Settings);
|
||||||
|
|
||||||
// Wait until url has been resolved before returning
|
var tries = 10;
|
||||||
var TRIES = 5;
|
var retryDelay = 500;
|
||||||
var RETRY_DELAY = 500; //ms
|
if (WaitForTorrent(hash, tries, retryDelay))
|
||||||
var ready = false;
|
|
||||||
|
|
||||||
for (var i = 0; i < TRIES; i++)
|
|
||||||
{
|
|
||||||
ready = _proxy.HasHashTorrent(hash, Settings);
|
|
||||||
if (ready)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.Sleep(RETRY_DELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ready)
|
|
||||||
{
|
{
|
||||||
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings);
|
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings);
|
||||||
|
|
||||||
@ -69,8 +55,8 @@ protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Debug("Magnet {0} could not be resolved in {1} tries at {2} ms intervals.", magnetLink, TRIES, RETRY_DELAY);
|
_logger.Debug("rTorrent could not resolve magnet {0}. Removing", magnetLink);
|
||||||
// Remove from client, since it is discarded
|
|
||||||
RemoveItem(hash, true);
|
RemoveItem(hash, true);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -80,6 +66,11 @@ protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string
|
|||||||
protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string hash, string filename, byte[] fileContent)
|
protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string hash, string filename, byte[] fileContent)
|
||||||
{
|
{
|
||||||
_proxy.AddTorrentFromFile(filename, fileContent, Settings);
|
_proxy.AddTorrentFromFile(filename, fileContent, Settings);
|
||||||
|
|
||||||
|
var tries = 2;
|
||||||
|
var retryDelay = 100;
|
||||||
|
if (WaitForTorrent(hash, tries, retryDelay))
|
||||||
|
{
|
||||||
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings);
|
_proxy.SetTorrentLabel(hash, Settings.TvCategory, Settings);
|
||||||
|
|
||||||
SetPriority(remoteEpisode, hash);
|
SetPriority(remoteEpisode, hash);
|
||||||
@ -89,6 +80,15 @@ protected override string AddFromTorrentFile(RemoteEpisode remoteEpisode, string
|
|||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Debug("rTorrent could not add file");
|
||||||
|
|
||||||
|
RemoveItem(hash, true);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string Name
|
public override string Name
|
||||||
{
|
{
|
||||||
@ -251,5 +251,22 @@ private void SetDownloadDirectory(string hash)
|
|||||||
_proxy.SetTorrentDownloadDirectory(hash, Settings.TvDirectory, Settings);
|
_proxy.SetTorrentDownloadDirectory(hash, Settings.TvDirectory, Settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool WaitForTorrent(string hash, int tries, int retryDelay)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < tries; i++)
|
||||||
|
{
|
||||||
|
if (_proxy.HasHashTorrent(hash, Settings))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(retryDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Could not find hash {0} in {1} tries at {2} ms intervals.", hash, tries, retryDelay);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user