Skip to content

Commit

Permalink
Fixed: Imported downloads not being removed when seeding goals are met
Browse files Browse the repository at this point in the history
Closes #1400
  • Loading branch information
markus101 authored and Qstick committed Oct 14, 2020
1 parent 1d58b33 commit e836b79
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/NzbDrone.Core/Download/DownloadProcessingService.cs
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.TrackedDownloads;
Expand Down Expand Up @@ -31,9 +32,13 @@ public class DownloadProcessingService : IExecute<ProcessMonitoredDownloadsComma
_logger = logger;
}

private void RemoveCompletedDownloads(List<TrackedDownload> trackedDownloads)
private void RemoveCompletedDownloads()
{
foreach (var trackedDownload in trackedDownloads.Where(c => c.DownloadItem.CanBeRemoved && c.State == TrackedDownloadState.Imported))
var trackedDownloads = _trackedDownloadService.GetTrackedDownloads()
.Where(t => !t.DownloadItem.Removed && t.DownloadItem.CanBeRemoved && t.State == TrackedDownloadState.Imported)
.ToList();

foreach (var trackedDownload in trackedDownloads)
{
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
}
Expand All @@ -54,21 +59,10 @@ public void Execute(ProcessMonitoredDownloadsCommand message)
if (trackedDownload.State == TrackedDownloadState.DownloadFailedPending)
{
_failedDownloadService.ProcessFailed(trackedDownload);
continue;
}

if (enableCompletedDownloadHandling && trackedDownload.State == TrackedDownloadState.ImportPending)
else if (enableCompletedDownloadHandling && trackedDownload.State == TrackedDownloadState.ImportPending)
{
_completedDownloadService.Import(trackedDownload);
continue;
}

if (removeCompletedDownloads &&
trackedDownload.DownloadItem.Removed &&
trackedDownload.DownloadItem.CanBeRemoved &&
trackedDownload.State == TrackedDownloadState.Imported)
{
_eventAggregator.PublishEvent(new DownloadCanBeRemovedEvent(trackedDownload));
}
}
catch (Exception e)
Expand All @@ -77,6 +71,12 @@ public void Execute(ProcessMonitoredDownloadsCommand message)
}
}

// Imported downloads are no longer trackable so process them after processing trackable downloads
if (removeCompletedDownloads)
{
RemoveCompletedDownloads();
}

_eventAggregator.PublishEvent(new DownloadsProcessedEvent());
}
}
Expand Down

0 comments on commit e836b79

Please sign in to comment.