1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

Fixed: Hide fallback pending releases if temporarily delayed.

Also batch changing of Pending Release Reason.
This commit is contained in:
Taloth Saldono 2018-03-27 15:28:31 +02:00 committed by Taloth
parent 67038ddd5e
commit c677736a8f
2 changed files with 22 additions and 42 deletions

View File

@ -212,7 +212,7 @@ public void should_not_add_to_pending_if_episode_was_grabbed()
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
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]
@ -226,7 +226,7 @@ public void should_add_to_pending_even_if_already_added_to_pending()
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
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]

View File

@ -40,9 +40,10 @@ public ProcessedDecisions ProcessDecisions(List<DownloadDecision> decisions)
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(qualifiedReports);
var grabbed = new List<DownloadDecision>();
var pending = new List<DownloadDecision>();
var failed = new List<DownloadDecision>();
var rejected = decisions.Where(d => d.Rejected).ToList();
var pendingAddQueue = new List<Tuple<DownloadDecision, PendingReleaseReason>>();
var usenetFailed = false;
var torrentFailed = false;
@ -59,15 +60,14 @@ public ProcessedDecisions ProcessDecisions(List<DownloadDecision> decisions)
if (report.TemporarilyRejected)
{
_pendingReleaseService.Add(report, PendingReleaseReason.Delay);
pending.Add(report);
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.Delay);
continue;
}
if (downloadProtocol == DownloadProtocol.Usenet && usenetFailed ||
downloadProtocol == DownloadProtocol.Torrent && torrentFailed)
{
failed.Add(report);
PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable);
continue;
}
@ -86,7 +86,7 @@ public ProcessedDecisions ProcessDecisions(List<DownloadDecision> decisions)
if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException)
{
_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)
{
@ -104,7 +104,10 @@ public ProcessedDecisions ProcessDecisions(List<DownloadDecision> decisions)
}
}
pending.AddRange(ProcessFailedGrabs(grabbed, failed));
if (pendingAddQueue.Any())
{
_pendingReleaseService.AddMany(pendingAddQueue);
}
return new ProcessedDecisions(grabbed, pending, rejected);
}
@ -126,45 +129,22 @@ private bool IsEpisodeProcessed(List<DownloadDecision> decisions, DownloadDecisi
.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>();
var stored = new List<DownloadDecision>();
// If a release was already grabbed with matching episodes we should store it as a fallback
// 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>>();
foreach (var report in failed)
if (IsEpisodeProcessed(grabbed, report) ||
IsEpisodeProcessed(pending, report))
{
// If a release was already grabbed with matching episodes we should store it as a 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);
}
reason = PendingReleaseReason.Fallback;
}
if (addQueue.Any())
{
_pendingReleaseService.AddMany(addQueue);
}
return pending;
queue.Add(Tuple.Create(report, reason));
pending.Add(report);
}
}
}