From 8c7c2ac29625b479d845865bc65796f440072d5c Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 21 Apr 2011 23:23:29 -0700 Subject: [PATCH] More work on indexers/jobs --- NzbDrone.Core.Test/IndexerProviderTest.cs | 2 +- .../Providers/Indexer/IndexerProviderBase.cs | 38 +++++++++++-------- NzbDrone.Core/Providers/IndexerProvider.cs | 4 +- NzbDrone.Core/Providers/Jobs/JobProvider.cs | 30 ++++++++------- NzbDrone.Core/Providers/Jobs/RssSyncJob.cs | 19 +++++----- NzbDrone.Web/Controllers/JobController.cs | 26 ------------- NzbDrone.Web/Controllers/SystemController.cs | 34 +++++++++++++++++ NzbDrone.Web/NzbDrone.Web.csproj | 7 ++-- NzbDrone.Web/Views/System/Indexers.cshtml | 9 +++++ .../{Job/index.cshtml => System/Jobs.cshtml} | 0 10 files changed, 99 insertions(+), 70 deletions(-) delete mode 100644 NzbDrone.Web/Controllers/JobController.cs create mode 100644 NzbDrone.Web/Controllers/SystemController.cs create mode 100644 NzbDrone.Web/Views/System/Indexers.cshtml rename NzbDrone.Web/Views/{Job/index.cshtml => System/Jobs.cshtml} (100%) diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index 302fc7d97..bd350e1df 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test //Act var indexerProvider = mocker.Resolve(); indexerProvider.InitializeIndexers(new List() { mocker.Resolve() }); - var indexers = indexerProvider.AllIndexers(); + var indexers = indexerProvider.All(); //Assert Assert.Count(1, indexers); diff --git a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index 886cff85d..be09fa51a 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -9,7 +9,7 @@ namespace NzbDrone.Core.Providers.Indexer { public abstract class IndexerProviderBase { - protected static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + protected readonly Logger _logger; protected readonly ConfigProvider _configProvider; protected readonly EpisodeProvider _episodeProvider; private readonly HttpProvider _httpProvider; @@ -30,6 +30,7 @@ namespace NzbDrone.Core.Providers.Indexer _httpProvider = httpProvider; _indexerProvider = indexerProvider; _historyProvider = historyProvider; + _logger = LogManager.GetLogger(GetType().ToString()); } /// @@ -56,25 +57,32 @@ namespace NzbDrone.Core.Providers.Indexer /// public void Fetch() { - Logger.Info("Fetching feeds from " + Settings.Name); + _logger.Info("Fetching feeds from " + Settings.Name); foreach (var url in Urls) { - Logger.Debug("Downloading RSS " + url); - var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items; - - foreach (var item in feed) + try { - ProcessItem(item); + _logger.Debug("Downloading RSS " + url); + var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items; + + foreach (var item in feed) + { + ProcessItem(item); + } + } + catch (Exception e) + { + _logger.ErrorException("An error occurred while processing feed", e); } } - Logger.Info("Finished processing feeds from " + Settings.Name); + _logger.Info("Finished processing feeds from " + Settings.Name); } private void ProcessItem(SyndicationItem feedItem) { - Logger.Info("Processing RSS feed item " + feedItem.Title.Text); + _logger.Info("Processing RSS feed item " + feedItem.Title.Text); var parseResult = ParseFeed(feedItem); @@ -82,25 +90,25 @@ namespace NzbDrone.Core.Providers.Indexer { if (!_seriesProvider.IsMonitored(parseResult.SeriesId)) { - Logger.Debug("{0} is present in the DB but not tracked. skipping.", parseResult.SeriesTitle); + _logger.Debug("{0} is present in the DB but not tracked. skipping.", parseResult.SeriesTitle); return; } if (!_seriesProvider.QualityWanted(parseResult.SeriesId, parseResult.Quality)) { - Logger.Debug("Post doesn't meet the quality requirements [{0}]. skipping.", parseResult.Quality); + _logger.Debug("Post doesn't meet the quality requirements [{0}]. skipping.", parseResult.Quality); return; } if (_seasonProvider.IsIgnored(parseResult.SeriesId, parseResult.SeasonNumber)) { - Logger.Debug("Season {0} is currently set to ignore. skipping.", parseResult.SeasonNumber); + _logger.Debug("Season {0} is currently set to ignore. skipping.", parseResult.SeasonNumber); return; } if (!_episodeProvider.IsNeeded(parseResult)) { - Logger.Debug("Episode {0} is not needed. skipping.", parseResult); + _logger.Debug("Episode {0} is not needed. skipping.", parseResult); return; } @@ -110,7 +118,7 @@ namespace NzbDrone.Core.Providers.Indexer { if (_historyProvider.Exists(episode.EpisodeId, parseResult.Quality, parseResult.Proper)) { - Logger.Debug("Episode in history: {0}", episode.ToString()); + _logger.Debug("Episode in history: {0}", episode.ToString()); continue; } @@ -148,7 +156,7 @@ namespace NzbDrone.Core.Providers.Indexer return CustomParser(item, episodeParseResult); } - Logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle); + _logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle); return CustomParser(item, episodeParseResult); } diff --git a/NzbDrone.Core/Providers/IndexerProvider.cs b/NzbDrone.Core/Providers/IndexerProvider.cs index 9f627d001..a5c085ae2 100644 --- a/NzbDrone.Core/Providers/IndexerProvider.cs +++ b/NzbDrone.Core/Providers/IndexerProvider.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Providers } - public virtual List AllIndexers() + public virtual List All() { return _repository.All().ToList(); } @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Providers { Logger.Info("Initializing indexers. Count {0}", indexers.Count); - var currentIndexers = AllIndexers(); + var currentIndexers = All(); foreach (var feedProvider in indexers) { diff --git a/NzbDrone.Core/Providers/Jobs/JobProvider.cs b/NzbDrone.Core/Providers/Jobs/JobProvider.cs index f2ed6949a..c748499e3 100644 --- a/NzbDrone.Core/Providers/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Providers/Jobs/JobProvider.cs @@ -166,25 +166,29 @@ namespace NzbDrone.Core.Providers.Jobs var settings = All().Where(j => j.TypeName == jobType.ToString()).FirstOrDefault(); - try + using (_notification = new ProgressNotification(timerClass.Name)) { - Logger.Info("Starting job '{0}'. Last execution {1}", settings.Name, settings.LastExecution); - settings.LastExecution = DateTime.Now; - var sw = Stopwatch.StartNew(); - using (_notification = new ProgressNotification(timerClass.Name)) + try { + Logger.Info("Starting job '{0}'. Last execution {1}", settings.Name, settings.LastExecution); + settings.LastExecution = DateTime.Now; + var sw = Stopwatch.StartNew(); + _notificationProvider.Register(_notification); timerClass.Start(_notification, targetId); _notification.Status = ProgressNotificationStatus.Completed; + + settings.Success = true; + sw.Stop(); + Logger.Info("Job '{0}' successfully completed in {1} seconds", timerClass.Name, sw.Elapsed.Minutes, + sw.Elapsed.Seconds); + } + catch (Exception e) + { + settings.Success = false; + Logger.ErrorException("An error has occurred while executing timer job " + timerClass.Name, e); + _notification.Status = ProgressNotificationStatus.Failed; } - settings.Success = true; - sw.Stop(); - Logger.Info("Job '{0}' successfully completed in {1} seconds", timerClass.Name, sw.Elapsed.Minutes, sw.Elapsed.Seconds); - } - catch (Exception e) - { - settings.Success = false; - Logger.ErrorException("An error has occurred while executing timer job " + timerClass.Name, e); } SaveSettings(settings); diff --git a/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs b/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs index 0dba9d549..cb56934ec 100644 --- a/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs +++ b/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs @@ -1,18 +1,21 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using NLog; using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers.Indexer; namespace NzbDrone.Core.Providers.Jobs { public class RssSyncJob : IJob { - private readonly IndexerProvider _indexerProvider; + private readonly IEnumerable _indexers; + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RssSyncJob(IndexerProvider indexerProvider) + public RssSyncJob(IEnumerable indexers) { - _indexerProvider = indexerProvider; + _indexers = indexers; } public string Name @@ -27,13 +30,9 @@ namespace NzbDrone.Core.Providers.Jobs public void Start(ProgressNotification notification, int targetId) { - Logger.Info("Doing Things!!!!"); - - var indexers = _indexerProvider.AllIndexers().Where(c => c.Enable); - - foreach (var indexerSetting in indexers) + foreach (var indexer in _indexers) { - + indexer.Fetch(); } } } diff --git a/NzbDrone.Web/Controllers/JobController.cs b/NzbDrone.Web/Controllers/JobController.cs deleted file mode 100644 index 3f14d0803..000000000 --- a/NzbDrone.Web/Controllers/JobController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; -using NzbDrone.Core.Providers.Jobs; - -namespace NzbDrone.Web.Controllers -{ - public class JobController : Controller - { - private readonly JobProvider _jobProvider; - - public JobController(JobProvider jobProvider) - { - _jobProvider = jobProvider; - } - - public ActionResult Index() - { - return View(_jobProvider.All()); - } - - - } -} diff --git a/NzbDrone.Web/Controllers/SystemController.cs b/NzbDrone.Web/Controllers/SystemController.cs new file mode 100644 index 000000000..dd0dfb69f --- /dev/null +++ b/NzbDrone.Web/Controllers/SystemController.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Jobs; + +namespace NzbDrone.Web.Controllers +{ + public class SystemController : Controller + { + private readonly JobProvider _jobProvider; + private readonly IndexerProvider _indexerProvider; + + public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider) + { + _jobProvider = jobProvider; + _indexerProvider = indexerProvider; + } + + public ActionResult Jobs() + { + return View(_jobProvider.All()); + } + + public ActionResult Indexers() + { + return View(_indexerProvider.All()); + } + + + } +} diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 03a029a06..478023e0a 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -219,7 +219,7 @@ - + Global.asax @@ -660,7 +660,7 @@ - + @@ -673,7 +673,7 @@ - + @@ -682,6 +682,7 @@ + diff --git a/NzbDrone.Web/Views/System/Indexers.cshtml b/NzbDrone.Web/Views/System/Indexers.cshtml new file mode 100644 index 000000000..639d8afe1 --- /dev/null +++ b/NzbDrone.Web/Views/System/Indexers.cshtml @@ -0,0 +1,9 @@ +@model IEnumerable +@section TitleContent{ +Indexers +} +@section MainContent{ + @{Html.Telerik().Grid(Model).Name("Grid") + .TableHtmlAttributes(new { @class = "Grid" }) + .Render();} +} diff --git a/NzbDrone.Web/Views/Job/index.cshtml b/NzbDrone.Web/Views/System/Jobs.cshtml similarity index 100% rename from NzbDrone.Web/Views/Job/index.cshtml rename to NzbDrone.Web/Views/System/Jobs.cshtml