More work on indexers/jobs
This commit is contained in:
parent
7e66871cb7
commit
8c7c2ac296
|
@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test
|
|||
//Act
|
||||
var indexerProvider = mocker.Resolve<IndexerProvider>();
|
||||
indexerProvider.InitializeIndexers(new List<IndexerProviderBase>() { mocker.Resolve<MockIndexerProvider>() });
|
||||
var indexers = indexerProvider.AllIndexers();
|
||||
var indexers = indexerProvider.All();
|
||||
|
||||
//Assert
|
||||
Assert.Count(1, indexers);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -56,25 +57,32 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
}
|
||||
|
||||
public virtual List<IndexerSetting> AllIndexers()
|
||||
public virtual List<IndexerSetting> All()
|
||||
{
|
||||
return _repository.All<IndexerSetting>().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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<IndexerProviderBase> _indexers;
|
||||
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RssSyncJob(IndexerProvider indexerProvider)
|
||||
public RssSyncJob(IEnumerable<IndexerProviderBase> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -219,7 +219,7 @@
|
|||
<Compile Include="Controllers\SeriesController.cs" />
|
||||
<Compile Include="Controllers\SettingsController.cs" />
|
||||
<Compile Include="Controllers\SharedController.cs" />
|
||||
<Compile Include="Controllers\JobController.cs" />
|
||||
<Compile Include="Controllers\SystemController.cs" />
|
||||
<Compile Include="Controllers\UpcomingController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
|
@ -660,7 +660,7 @@
|
|||
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
|
||||
<Content Include="Views\Web.config" />
|
||||
<Content Include="Views\Settings\Indexers.cshtml" />
|
||||
<Content Include="Views\Job\index.cshtml" />
|
||||
<Content Include="Views\System\Jobs.cshtml" />
|
||||
<Content Include="Views\Settings\Downloads.cshtml" />
|
||||
<Content Include="Views\Settings\EpisodeSorting.cshtml" />
|
||||
<Content Include="Views\Settings\General.cshtml" />
|
||||
|
@ -673,7 +673,7 @@
|
|||
<Content Include="Views\Settings\Index.cshtml" />
|
||||
<Content Include="Views\_ViewStart.cshtml" />
|
||||
<Content Include="Views\History\Index.cshtml" />
|
||||
<Content Include="Views\Log\Index.cshtml" />
|
||||
<Content Include="Views\Log\index.cshtml" />
|
||||
<Content Include="Views\Upcoming\Index.cshtml" />
|
||||
<Content Include="Views\Series\Details.cshtml" />
|
||||
<Content Include="Views\Series\Edit.cshtml" />
|
||||
|
@ -682,6 +682,7 @@
|
|||
<Content Include="Views\Series\SeriesSearchResults.cshtml" />
|
||||
<Content Include="Views\Shared\Error.cshtml" />
|
||||
<Content Include="Views\Settings\UserProfileSection.cshtml" />
|
||||
<Content Include="Views\System\Indexers.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
@model IEnumerable<NzbDrone.Core.Repository.IndexerSetting>
|
||||
@section TitleContent{
|
||||
Indexers
|
||||
}
|
||||
@section MainContent{
|
||||
@{Html.Telerik().Grid(Model).Name("Grid")
|
||||
.TableHtmlAttributes(new { @class = "Grid" })
|
||||
.Render();}
|
||||
}
|
Loading…
Reference in New Issue