diff --git a/NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs b/NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs new file mode 100644 index 000000000..b6e567ce1 --- /dev/null +++ b/NzbDrone.Core.Test/JobTests/RssSyncJobTest.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Jobs; +using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common.AutoMoq; + +namespace NzbDrone.Core.Test.JobTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class RssSyncJobTest : CoreTest + { + public void WithMinutes(int minutes) + { + Mocker.GetMock().SetupGet(s => s.RssSyncInterval).Returns(minutes); + } + + [TestCase(10)] + [TestCase(15)] + [TestCase(25)] + [TestCase(60)] + [TestCase(120)] + public void should_use_value_from_config_provider(int minutes) + { + WithMinutes(minutes); + Mocker.Resolve().DefaultInterval.Should().Be(TimeSpan.FromMinutes(minutes)); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 5c0d764d7..42e947a8a 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -142,6 +142,7 @@ + diff --git a/NzbDrone.Core/Jobs/JobProvider.cs b/NzbDrone.Core/Jobs/JobProvider.cs index 03e2b50d2..0f3c239ee 100644 --- a/NzbDrone.Core/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Jobs/JobProvider.cs @@ -96,7 +96,9 @@ namespace NzbDrone.Core.Jobs jobDefinition.Enable = job.DefaultInterval.TotalSeconds > 0; jobDefinition.Name = job.Name; + jobDefinition.Interval = Convert.ToInt32(job.DefaultInterval.TotalMinutes); + //Todo: Need to have a way for users to change this and not have it overwritten on start-up. SaveDefinition(jobDefinition); } @@ -196,6 +198,11 @@ namespace NzbDrone.Core.Jobs return true; } + public virtual JobDefinition GetDefinition(Type type) + { + return _database.Single("WHERE TypeName = @0", type.ToString()); + } + private void ProcessQueue() { try @@ -321,7 +328,5 @@ namespace NzbDrone.Core.Jobs logger.Trace("resetting queue processor thread"); _jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" }; } - - } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/RssSyncJob.cs b/NzbDrone.Core/Jobs/RssSyncJob.cs index 66703cdac..a1f63f75e 100644 --- a/NzbDrone.Core/Jobs/RssSyncJob.cs +++ b/NzbDrone.Core/Jobs/RssSyncJob.cs @@ -7,6 +7,7 @@ using NLog; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.DecisionEngine; using NzbDrone.Core.Providers.Indexer; using StackExchange.Profiling; @@ -20,19 +21,22 @@ namespace NzbDrone.Core.Jobs private readonly MonitoredEpisodeSpecification _isMonitoredEpisodeSpecification; private readonly AllowedDownloadSpecification _allowedDownloadSpecification; private readonly UpgradeHistorySpecification _upgradeHistorySpecification; + private readonly ConfigProvider _configProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); [Inject] public RssSyncJob(DownloadProvider downloadProvider, IndexerProvider indexerProvider, - MonitoredEpisodeSpecification isMonitoredEpisodeSpecification, AllowedDownloadSpecification allowedDownloadSpecification, UpgradeHistorySpecification upgradeHistorySpecification) + MonitoredEpisodeSpecification isMonitoredEpisodeSpecification, AllowedDownloadSpecification allowedDownloadSpecification, + UpgradeHistorySpecification upgradeHistorySpecification, ConfigProvider configProvider) { _downloadProvider = downloadProvider; _indexerProvider = indexerProvider; _isMonitoredEpisodeSpecification = isMonitoredEpisodeSpecification; _allowedDownloadSpecification = allowedDownloadSpecification; _upgradeHistorySpecification = upgradeHistorySpecification; + _configProvider = configProvider; } public string Name @@ -42,7 +46,7 @@ namespace NzbDrone.Core.Jobs public TimeSpan DefaultInterval { - get { return TimeSpan.FromMinutes(25); } + get { return TimeSpan.FromMinutes(_configProvider.RssSyncInterval); } } public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index 0a371981d..09f83adae 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -532,6 +532,12 @@ namespace NzbDrone.Core.Providers.Core set { SetValue("RecycleBin", value); } } + public virtual int RssSyncInterval + { + get { return GetValueInt("RssSyncInterval", 25); } + set { SetValue("RssSyncInterval", value); } + } + private string GetValue(string key) { return GetValue(key, String.Empty); diff --git a/NzbDrone.Web/Content/IndexerSettings.css b/NzbDrone.Web/Content/IndexerSettings.css index 688e89480..278331b59 100644 --- a/NzbDrone.Web/Content/IndexerSettings.css +++ b/NzbDrone.Web/Content/IndexerSettings.css @@ -91,7 +91,7 @@ overflow: auto; } -.retentionContainer +.indexer-global-settings { padding-top: 20px; overflow: hidden; diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 400b3d692..d5242f877 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.Model; using NzbDrone.Core.Helpers; +using NzbDrone.Core.Jobs; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; @@ -32,18 +33,21 @@ namespace NzbDrone.Web.Controllers private readonly ConfigFileProvider _configFileProvider; private readonly NewznabProvider _newznabProvider; private readonly MetadataProvider _metadataProvider; + private readonly JobProvider _jobProvider; public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider, QualityProvider qualityProvider, AutoConfigureProvider autoConfigureProvider, SeriesProvider seriesProvider, ExternalNotificationProvider externalNotificationProvider, QualityTypeProvider qualityTypeProvider, ConfigFileProvider configFileProvider, - NewznabProvider newznabProvider, MetadataProvider metadataProvider) + NewznabProvider newznabProvider, MetadataProvider metadataProvider, + JobProvider jobProvider) { _externalNotificationProvider = externalNotificationProvider; _qualityTypeProvider = qualityTypeProvider; _configFileProvider = configFileProvider; _newznabProvider = newznabProvider; _metadataProvider = metadataProvider; + _jobProvider = jobProvider; _configProvider = configProvider; _indexerProvider = indexerProvider; _qualityProvider = qualityProvider; @@ -84,6 +88,8 @@ namespace NzbDrone.Web.Controllers NzbIndexEnabled = _indexerProvider.GetSettings(typeof(NzbIndex)).Enable, NzbClubEnabled = _indexerProvider.GetSettings(typeof(NzbClub)).Enable, + RssSyncInterval = _configProvider.RssSyncInterval, + NewznabDefinitions = _newznabProvider.All(), }); } @@ -401,6 +407,13 @@ namespace NzbDrone.Web.Controllers _configProvider.FileSharingTalkUid = data.FileSharingTalkUid; _configProvider.FileSharingTalkSecret = data.FileSharingTalkSecret; + //Save the interval to config and immediately apply it the the job (to avoid a restart) + _configProvider.RssSyncInterval = data.RssSyncInterval; + + var rssSyncJob = _jobProvider.GetDefinition(typeof(RssSyncJob)); + rssSyncJob.Interval = data.RssSyncInterval; + _jobProvider.SaveDefinition(rssSyncJob); + try { if (data.NewznabDefinitions != null) diff --git a/NzbDrone.Web/Models/IndexerSettingsModel.cs b/NzbDrone.Web/Models/IndexerSettingsModel.cs index 9d7cf3cca..0d25c5fdb 100644 --- a/NzbDrone.Web/Models/IndexerSettingsModel.cs +++ b/NzbDrone.Web/Models/IndexerSettingsModel.cs @@ -103,6 +103,13 @@ namespace NzbDrone.Web.Models [Description("Usenet provider retention in days (0 = unlimited)")] public int Retention { get; set; } + [DisplayName("RSS Sync Interval")] + [Description("Check for new episodes every X minutes")] + [DisplayFormat(ConvertEmptyStringToNull = false)] + [Required(AllowEmptyStrings = false, ErrorMessage = "You must enter a valid time in minutes")] + [Range(15, 240, ErrorMessage = "Interval must be between 15 and 240 minutes")] + public int RssSyncInterval { get; set; } + public List NewznabDefinitions { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Indexers.cshtml b/NzbDrone.Web/Views/Settings/Indexers.cshtml index 93ef790fd..909a892cc 100644 --- a/NzbDrone.Web/Views/Settings/Indexers.cshtml +++ b/NzbDrone.Web/Views/Settings/Indexers.cshtml @@ -160,13 +160,19 @@ -
+
@Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") @Html.TextBoxFor(m => m.Retention, new { @class = "inputClass" }) + + + @Html.TextBoxFor(m => m.RssSyncInterval, new { @class = "inputClass" })