diff --git a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs index 170e0a0b9..6e0293182 100644 --- a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs @@ -95,7 +95,7 @@ namespace NzbDrone.Core.Test.Download .Setup(s => s.GetHistory(0, 20)) .Returns(new List()); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); Mocker.GetMock() .Verify(s => s.BetweenDates(It.IsAny(), It.IsAny(), HistoryEventType.Grabbed), @@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.Download .Setup(s => s.GetHistory(0, 20)) .Returns(_completed); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); Mocker.GetMock() .Verify(s => s.BetweenDates(It.IsAny(), It.IsAny(), HistoryEventType.Grabbed), @@ -126,7 +126,7 @@ namespace NzbDrone.Core.Test.Download GivenNoGrabbedHistory(); GivenFailedDownloadClientHistory(); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); VerifyNoFailedDownloads(); } @@ -146,7 +146,7 @@ namespace NzbDrone.Core.Test.Download history.First().Data.Add("downloadClient", "SabnzbdClient"); history.First().Data.Add("downloadClientId", _failed.First().Id); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); VerifyNoFailedDownloads(); } @@ -166,7 +166,7 @@ namespace NzbDrone.Core.Test.Download history.First().Data.Add("downloadClient", "SabnzbdClient"); history.First().Data.Add("downloadClientId", _failed.First().Id); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); VerifyFailedDownloads(); } @@ -189,7 +189,7 @@ namespace NzbDrone.Core.Test.Download h.Data.Add("downloadClientId", _failed.First().Id); }); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); VerifyFailedDownloads(2); } @@ -201,7 +201,7 @@ namespace NzbDrone.Core.Test.Download .SetupGet(s => s.EnableFailedDownloadHandling) .Returns(false); - Subject.Execute(new FailedDownloadCommand()); + Subject.Execute(new CheckForFailedDownloadCommand()); VerifyNoFailedDownloads(); } diff --git a/src/NzbDrone.Core/Download/FailedDownloadCommand.cs b/src/NzbDrone.Core/Download/CheckForFailedDownloadCommand.cs similarity index 62% rename from src/NzbDrone.Core/Download/FailedDownloadCommand.cs rename to src/NzbDrone.Core/Download/CheckForFailedDownloadCommand.cs index 864921ba1..a1714d35f 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadCommand.cs +++ b/src/NzbDrone.Core/Download/CheckForFailedDownloadCommand.cs @@ -2,7 +2,7 @@ namespace NzbDrone.Core.Download { - public class FailedDownloadCommand : Command + public class CheckForFailedDownloadCommand : Command { } diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 456c5d007..4671ec150 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Net; using NLog; using NzbDrone.Core.Configuration; using NzbDrone.Core.History; @@ -13,7 +14,7 @@ namespace NzbDrone.Core.Download void MarkAsFailed(int historyId); } - public class FailedDownloadService : IFailedDownloadService, IExecute + public class FailedDownloadService : IFailedDownloadService, IExecute { private readonly IProvideDownloadClient _downloadClientProvider; private readonly IHistoryService _historyService; @@ -40,22 +41,7 @@ namespace NzbDrone.Core.Download public void MarkAsFailed(int historyId) { var item = _historyService.Get(historyId); - PublishDownloadFailedEvent(new List {item}, "Manually marked as failed"); - } - - private void CheckForFailedDownloads() - { - if (!_configService.EnableFailedDownloadHandling) - { - _logger.Trace("Failed Download Handling is not enabled"); - return; - } - - var grabbedHistory = _historyService.Grabbed(); - var failedHistory = _historyService.Failed(); - - CheckQueue(grabbedHistory, failedHistory); - CheckHistory(grabbedHistory, failedHistory); + PublishDownloadFailedEvent(new List { item }, "Manually marked as failed"); } private void CheckQueue(List grabbedHistory, List failedHistory) @@ -163,9 +149,19 @@ namespace NzbDrone.Core.Download return _downloadClientProvider.GetDownloadClient(); } - public void Execute(FailedDownloadCommand message) + public void Execute(CheckForFailedDownloadCommand message) { - CheckForFailedDownloads(); + if (!_configService.EnableFailedDownloadHandling) + { + _logger.Trace("Failed Download Handling is not enabled"); + return; + } + + var grabbedHistory = _historyService.Grabbed(); + var failedHistory = _historyService.Failed(); + + CheckQueue(grabbedHistory, failedHistory); + CheckHistory(grabbedHistory, failedHistory); } } } diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index d87ded193..141cd729d 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Jobs new ScheduledTask{ Interval = 3*60, TypeName = typeof(UpdateSceneMappingCommand).FullName}, new ScheduledTask{ Interval = 1, TypeName = typeof(TrackedCommandCleanupCommand).FullName}, new ScheduledTask{ Interval = 24*60, TypeName = typeof(HousekeepingCommand).FullName}, - new ScheduledTask{ Interval = 1, TypeName = typeof(FailedDownloadCommand).FullName} + new ScheduledTask{ Interval = 1, TypeName = typeof(CheckForFailedDownloadCommand).FullName} }; var currentTasks = _scheduledTaskRepository.All(); diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 14c94c1e0..6f8263af9 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -233,7 +233,7 @@ - +