mirror of
https://github.com/Sonarr/Sonarr
synced 2025-01-18 21:29:46 +00:00
Fixed: Hide fallback pending releases if temporarily delayed.
Also batch changing of Pending Release Reason.
This commit is contained in:
parent
67038ddd5e
commit
c677736a8f
2 changed files with 22 additions and 42 deletions
|
@ -212,7 +212,7 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||||
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
||||||
|
|
||||||
Subject.ProcessDecisions(decisions);
|
Subject.ProcessDecisions(decisions);
|
||||||
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.Add(It.IsAny<DownloadDecision>(), It.IsAny<PendingReleaseReason>()), Times.Never());
|
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.AddMany(It.IsAny<List<Tuple<DownloadDecision, PendingReleaseReason>>>()), Times.Never());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -226,7 +226,7 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||||
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
||||||
|
|
||||||
Subject.ProcessDecisions(decisions);
|
Subject.ProcessDecisions(decisions);
|
||||||
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.Add(It.IsAny<DownloadDecision>(), It.IsAny<PendingReleaseReason>()), Times.Exactly(2));
|
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.AddMany(It.IsAny<List<Tuple<DownloadDecision, PendingReleaseReason>>>()), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -40,9 +40,10 @@ namespace NzbDrone.Core.Download
|
||||||
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(qualifiedReports);
|
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(qualifiedReports);
|
||||||
var grabbed = new List<DownloadDecision>();
|
var grabbed = new List<DownloadDecision>();
|
||||||
var pending = new List<DownloadDecision>();
|
var pending = new List<DownloadDecision>();
|
||||||
var failed = new List<DownloadDecision>();
|
|
||||||
var rejected = decisions.Where(d => d.Rejected).ToList();
|
var rejected = decisions.Where(d => d.Rejected).ToList();
|
||||||
|
|
||||||
|
var pendingAddQueue = new List<Tuple<DownloadDecision, PendingReleaseReason>>();
|
||||||
|
|
||||||
var usenetFailed = false;
|
var usenetFailed = false;
|
||||||
var torrentFailed = false;
|
var torrentFailed = false;
|
||||||
|
|
||||||
|
@ -59,15 +60,14 @@ namespace NzbDrone.Core.Download
|
||||||
|
|
||||||
if (report.TemporarilyRejected)
|
if (report.TemporarilyRejected)
|
||||||
{
|
{
|
||||||
_pendingReleaseService.Add(report, PendingReleaseReason.Delay);
|
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.Delay);
|
||||||
pending.Add(report);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadProtocol == DownloadProtocol.Usenet && usenetFailed ||
|
if (downloadProtocol == DownloadProtocol.Usenet && usenetFailed ||
|
||||||
downloadProtocol == DownloadProtocol.Torrent && torrentFailed)
|
downloadProtocol == DownloadProtocol.Torrent && torrentFailed)
|
||||||
{
|
{
|
||||||
failed.Add(report);
|
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ namespace NzbDrone.Core.Download
|
||||||
if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException)
|
if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException)
|
||||||
{
|
{
|
||||||
_logger.Debug(ex, "Failed to send release to download client, storing until later. " + remoteEpisode);
|
_logger.Debug(ex, "Failed to send release to download client, storing until later. " + remoteEpisode);
|
||||||
failed.Add(report);
|
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable);
|
||||||
|
|
||||||
if (downloadProtocol == DownloadProtocol.Usenet)
|
if (downloadProtocol == DownloadProtocol.Usenet)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,10 @@ namespace NzbDrone.Core.Download
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pending.AddRange(ProcessFailedGrabs(grabbed, failed));
|
if (pendingAddQueue.Any())
|
||||||
|
{
|
||||||
|
_pendingReleaseService.AddMany(pendingAddQueue);
|
||||||
|
}
|
||||||
|
|
||||||
return new ProcessedDecisions(grabbed, pending, rejected);
|
return new ProcessedDecisions(grabbed, pending, rejected);
|
||||||
}
|
}
|
||||||
|
@ -126,45 +129,22 @@ namespace NzbDrone.Core.Download
|
||||||
.Any();
|
.Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DownloadDecision> ProcessFailedGrabs(List<DownloadDecision> grabbed, List<DownloadDecision> failed)
|
private void PreparePending(List<Tuple<DownloadDecision, PendingReleaseReason>> queue, List<DownloadDecision> grabbed, List<DownloadDecision> pending, DownloadDecision report, PendingReleaseReason reason)
|
||||||
{
|
{
|
||||||
var pending = new List<DownloadDecision>();
|
// If a release was already grabbed with matching episodes we should store it as a fallback
|
||||||
var stored = new List<DownloadDecision>();
|
// and filter it out the next time it is processed.
|
||||||
|
// If a higher quality release failed to add to the download client, but a lower quality release
|
||||||
|
// was sent to another client we still list it normally so it apparent that it'll grab next time.
|
||||||
|
// Delayed is treated the same, but only the first is listed the subsequent items as stored as Fallback.
|
||||||
|
|
||||||
var addQueue = new List<Tuple<DownloadDecision, PendingReleaseReason>>();
|
if (IsEpisodeProcessed(grabbed, report) ||
|
||||||
|
IsEpisodeProcessed(pending, report))
|
||||||
foreach (var report in failed)
|
|
||||||
{
|
{
|
||||||
// If a release was already grabbed with matching episodes we should store it as a fallback
|
reason = PendingReleaseReason.Fallback;
|
||||||
// and filter it out the next time it is processed incase a higher quality release failed to
|
|
||||||
// add to the download client, but a lower quality release was sent to another client
|
|
||||||
// If the release wasn't grabbed already, but was already stored, store it as a fallback,
|
|
||||||
// otherwise store it as DownloadClientUnavailable.
|
|
||||||
|
|
||||||
if (IsEpisodeProcessed(grabbed, report))
|
|
||||||
{
|
|
||||||
addQueue.Add(Tuple.Create(report, PendingReleaseReason.Fallback));
|
|
||||||
pending.Add(report);
|
|
||||||
}
|
|
||||||
else if (IsEpisodeProcessed(stored, report))
|
|
||||||
{
|
|
||||||
addQueue.Add(Tuple.Create(report, PendingReleaseReason.Fallback));
|
|
||||||
pending.Add(report);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addQueue.Add(Tuple.Create(report, PendingReleaseReason.DownloadClientUnavailable));
|
|
||||||
pending.Add(report);
|
|
||||||
stored.Add(report);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addQueue.Any())
|
queue.Add(Tuple.Create(report, reason));
|
||||||
{
|
pending.Add(report);
|
||||||
_pendingReleaseService.AddMany(addQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pending;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue