From 083f649b5c4fece4231a11be26e116768bfdb601 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 5 Aug 2013 22:22:58 -0700 Subject: [PATCH] User can now configure RSS Sync Interval --- NzbDrone.Core/Configuration/ConfigService.cs | 15 ++++++++++++++- .../Configuration/Events/ConfigSavedEvent.cs | 8 ++++++++ NzbDrone.Core/Configuration/IConfigService.cs | 1 + NzbDrone.Core/Jobs/TaskManager.cs | 18 ++++++++++++++---- NzbDrone.Core/NzbDrone.Core.csproj | 1 + UI/Settings/Indexers/Options/ViewTemplate.html | 18 ++++++++++++------ 6 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index fe0896dfe..3596d596a 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; @@ -16,12 +18,14 @@ public enum ConfigKey public class ConfigService : IConfigService { private readonly IConfigRepository _repository; + private readonly IMessageAggregator _messageAggregator; private readonly Logger _logger; private static Dictionary _cache; - public ConfigService(IConfigRepository repository, Logger logger) + public ConfigService(IConfigRepository repository, IMessageAggregator messageAggregator, Logger logger) { _repository = repository; + _messageAggregator = messageAggregator; _logger = logger; _cache = new Dictionary(); } @@ -63,6 +67,8 @@ public void SaveValues(Dictionary configValues) if (!equal) SetValue(configValue.Key, configValue.Value.ToString()); } + + _messageAggregator.PublishEvent(new ConfigSavedEvent()); } public String SabHost @@ -238,6 +244,13 @@ public string ReleaseRestrictions set { SetValue("ReleaseRestrictions", value); } } + public Int32 RssSyncInterval + { + get { return GetValueInt("RssSyncInterval", 15); } + + set { SetValue("RssSyncInterval", value); } + } + private string GetValue(string key) { return GetValue(key, String.Empty); diff --git a/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs b/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs new file mode 100644 index 000000000..3700833e4 --- /dev/null +++ b/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.Configuration.Events +{ + public class ConfigSavedEvent : IEvent + { + } +} diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index 3cb7a7fee..b71671b13 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -36,6 +36,7 @@ public interface IConfigService PriorityType NzbgetRecentTvPriority { get; set; } PriorityType NzbgetOlderTvPriority { get; set; } string ReleaseRestrictions { get; set; } + Int32 RssSyncInterval { get; set; } void SaveValues(Dictionary configValues); } } diff --git a/NzbDrone.Core/Jobs/TaskManager.cs b/NzbDrone.Core/Jobs/TaskManager.cs index c309f6697..4c82da90a 100644 --- a/NzbDrone.Core/Jobs/TaskManager.cs +++ b/NzbDrone.Core/Jobs/TaskManager.cs @@ -3,6 +3,8 @@ using System.Linq; using NLog; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Indexers; using NzbDrone.Core.Instrumentation.Commands; using NzbDrone.Core.Lifecycle; @@ -18,18 +20,19 @@ public interface ITaskManager IList GetPending(); } - public class TaskManager : IHandle, IHandleAsync, ITaskManager + public class TaskManager : ITaskManager, IHandle, IHandleAsync, IHandleAsync { private readonly IScheduledTaskRepository _scheduledTaskRepository; + private readonly IConfigService _configService; private readonly Logger _logger; - public TaskManager(IScheduledTaskRepository scheduledTaskRepository, Logger logger) + public TaskManager(IScheduledTaskRepository scheduledTaskRepository, IConfigService configService, Logger logger) { _scheduledTaskRepository = scheduledTaskRepository; + _configService = configService; _logger = logger; } - public IList GetPending() { return _scheduledTaskRepository.All().Where(c => c.LastExecution.AddMinutes(c.Interval) < DateTime.UtcNow).ToList(); @@ -39,7 +42,7 @@ public void Handle(ApplicationStartedEvent message) { var defaultTasks = new[] { - new ScheduledTask{ Interval = 15, TypeName = typeof(RssSyncCommand).FullName}, + new ScheduledTask{ Interval = _configService.RssSyncInterval, TypeName = typeof(RssSyncCommand).FullName}, new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappingsCommand).FullName}, new ScheduledTask{ Interval = 12*60, TypeName = typeof(RefreshSeriesCommand).FullName}, new ScheduledTask{ Interval = 1, TypeName = typeof(DownloadedEpisodesScanCommand).FullName}, @@ -80,5 +83,12 @@ public void HandleAsync(CommandExecutedEvent message) _scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, DateTime.UtcNow); } } + + public void HandleAsync(ConfigSavedEvent message) + { + var rss = _scheduledTaskRepository.GetDefinition(typeof (RssSyncCommand)); + rss.Interval = _configService.RssSyncInterval; + _scheduledTaskRepository.Update(rss); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 3b60e5f03..1ca328194 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -117,6 +117,7 @@ + diff --git a/UI/Settings/Indexers/Options/ViewTemplate.html b/UI/Settings/Indexers/Options/ViewTemplate.html index 0ed820a02..7c5ea1238 100644 --- a/UI/Settings/Indexers/Options/ViewTemplate.html +++ b/UI/Settings/Indexers/Options/ViewTemplate.html @@ -9,22 +9,28 @@ - - +
+ - - - - +
+ + + + + +
+
+ + Newline-delimited set of rules