Fixed: Don't attempt to fetch a release if the download client is disabled

Mark McDowall 7 years ago
parent 6626397350
commit 5372ed5d40
No known key found for this signature in database
GPG Key ID: D4CEFA9A718052E0

@ -22,6 +22,7 @@ namespace NzbDrone.Core.Test.Download
{ {
private RemoteEpisode _parseResult; private RemoteEpisode _parseResult;
private List<IDownloadClient> _downloadClients; private List<IDownloadClient> _downloadClients;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
@ -180,7 +181,7 @@ namespace NzbDrone.Core.Test.Download
} }
[Test] [Test]
public void should_not_attempt_download_if_client_isnt_configure() public void should_not_attempt_download_if_client_isnt_configured()
{ {
Assert.Throws<DownloadClientUnavailableException>(() => Subject.DownloadReport(_parseResult)); Assert.Throws<DownloadClientUnavailableException>(() => Subject.DownloadReport(_parseResult));
@ -188,6 +189,21 @@ namespace NzbDrone.Core.Test.Download
VerifyEventNotPublished<EpisodeGrabbedEvent>(); VerifyEventNotPublished<EpisodeGrabbedEvent>();
} }
[Test]
public void should_not_attempt_download_if_client_is_disabled()
{
WithUsenetClient();
Mocker.GetMock<IDownloadClientStatusService>()
.Setup(v => v.IsDisabled(It.IsAny<int>()))
.Returns(true);
Assert.Throws<DownloadClientUnavailableException>(() => Subject.DownloadReport(_parseResult));
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
VerifyEventNotPublished<EpisodeGrabbedEvent>();
}
[Test] [Test]
public void should_send_download_to_correct_usenet_client() public void should_send_download_to_correct_usenet_client()
{ {

@ -1,4 +1,4 @@
using System; using System;
using NLog; using NLog;
using NzbDrone.Common.EnsureThat; using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -56,6 +56,11 @@ namespace NzbDrone.Core.Download
throw new DownloadClientUnavailableException($"{remoteEpisode.Release.DownloadProtocol} Download client isn't configured yet"); throw new DownloadClientUnavailableException($"{remoteEpisode.Release.DownloadProtocol} Download client isn't configured yet");
} }
if (_downloadClientStatusService.IsDisabled(downloadClient.Definition.Id))
{
throw new DownloadClientUnavailableException($"{downloadClient.Name} is disabled due to recent failues");
}
// Limit grabs to 2 per second. // Limit grabs to 2 per second.
if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteEpisode.Release.DownloadUrl.StartsWith("magnet:")) if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteEpisode.Release.DownloadUrl.StartsWith("magnet:"))
{ {

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
@ -10,6 +10,7 @@ namespace NzbDrone.Core.ThingiProvider.Status
public interface IProviderStatusServiceBase<TModel> public interface IProviderStatusServiceBase<TModel>
where TModel : ProviderStatusBase, new() where TModel : ProviderStatusBase, new()
{ {
bool IsDisabled(int providerId);
List<TModel> GetBlockedProviders(); List<TModel> GetBlockedProviders();
void RecordSuccess(int providerId); void RecordSuccess(int providerId);
void RecordFailure(int providerId, TimeSpan minimumBackOff = default(TimeSpan)); void RecordFailure(int providerId, TimeSpan minimumBackOff = default(TimeSpan));
@ -36,6 +37,11 @@ namespace NzbDrone.Core.ThingiProvider.Status
_logger = logger; _logger = logger;
} }
public bool IsDisabled(int providerId)
{
return GetProviderStatus(providerId).IsDisabled();
}
public virtual List<TModel> GetBlockedProviders() public virtual List<TModel> GetBlockedProviders()
{ {
return _providerStatusRepository.All().Where(v => v.IsDisabled()).ToList(); return _providerStatusRepository.All().Where(v => v.IsDisabled()).ToList();

Loading…
Cancel
Save