mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
More work on indexers/jobs
This commit is contained in:
parent
7e66871cb7
commit
8c7c2ac296
@ -48,7 +48,7 @@ public void Init_indexer_test()
|
|||||||
//Act
|
//Act
|
||||||
var indexerProvider = mocker.Resolve<IndexerProvider>();
|
var indexerProvider = mocker.Resolve<IndexerProvider>();
|
||||||
indexerProvider.InitializeIndexers(new List<IndexerProviderBase>() { mocker.Resolve<MockIndexerProvider>() });
|
indexerProvider.InitializeIndexers(new List<IndexerProviderBase>() { mocker.Resolve<MockIndexerProvider>() });
|
||||||
var indexers = indexerProvider.AllIndexers();
|
var indexers = indexerProvider.All();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
Assert.Count(1, indexers);
|
Assert.Count(1, indexers);
|
||||||
|
@ -9,7 +9,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||||||
{
|
{
|
||||||
public abstract class IndexerProviderBase
|
public abstract class IndexerProviderBase
|
||||||
{
|
{
|
||||||
protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
protected readonly Logger _logger;
|
||||||
protected readonly ConfigProvider _configProvider;
|
protected readonly ConfigProvider _configProvider;
|
||||||
protected readonly EpisodeProvider _episodeProvider;
|
protected readonly EpisodeProvider _episodeProvider;
|
||||||
private readonly HttpProvider _httpProvider;
|
private readonly HttpProvider _httpProvider;
|
||||||
@ -30,6 +30,7 @@ protected IndexerProviderBase(SeriesProvider seriesProvider, SeasonProvider seas
|
|||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_indexerProvider = indexerProvider;
|
_indexerProvider = indexerProvider;
|
||||||
_historyProvider = historyProvider;
|
_historyProvider = historyProvider;
|
||||||
|
_logger = LogManager.GetLogger(GetType().ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -56,25 +57,32 @@ protected IndexerSetting Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Fetch()
|
public void Fetch()
|
||||||
{
|
{
|
||||||
Logger.Info("Fetching feeds from " + Settings.Name);
|
_logger.Info("Fetching feeds from " + Settings.Name);
|
||||||
|
|
||||||
foreach (var url in Urls)
|
foreach (var url in Urls)
|
||||||
{
|
{
|
||||||
Logger.Debug("Downloading RSS " + url);
|
try
|
||||||
var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
|
|
||||||
|
|
||||||
foreach (var item in feed)
|
|
||||||
{
|
{
|
||||||
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)
|
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);
|
var parseResult = ParseFeed(feedItem);
|
||||||
|
|
||||||
@ -82,25 +90,25 @@ private void ProcessItem(SyndicationItem feedItem)
|
|||||||
{
|
{
|
||||||
if (!_seriesProvider.IsMonitored(parseResult.SeriesId))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_seriesProvider.QualityWanted(parseResult.SeriesId, parseResult.Quality))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_seasonProvider.IsIgnored(parseResult.SeriesId, parseResult.SeasonNumber))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_episodeProvider.IsNeeded(parseResult))
|
if (!_episodeProvider.IsNeeded(parseResult))
|
||||||
{
|
{
|
||||||
Logger.Debug("Episode {0} is not needed. skipping.", parseResult);
|
_logger.Debug("Episode {0} is not needed. skipping.", parseResult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +118,7 @@ private void ProcessItem(SyndicationItem feedItem)
|
|||||||
{
|
{
|
||||||
if (_historyProvider.Exists(episode.EpisodeId, parseResult.Quality, parseResult.Proper))
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +156,7 @@ protected EpisodeParseResult ParseFeed(SyndicationItem item)
|
|||||||
return CustomParser(item, episodeParseResult);
|
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);
|
return CustomParser(item, episodeParseResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public IndexerProvider()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<IndexerSetting> AllIndexers()
|
public virtual List<IndexerSetting> All()
|
||||||
{
|
{
|
||||||
return _repository.All<IndexerSetting>().ToList();
|
return _repository.All<IndexerSetting>().ToList();
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ public virtual void InitializeIndexers(IList<IndexerProviderBase> indexers)
|
|||||||
{
|
{
|
||||||
Logger.Info("Initializing indexers. Count {0}", indexers.Count);
|
Logger.Info("Initializing indexers. Count {0}", indexers.Count);
|
||||||
|
|
||||||
var currentIndexers = AllIndexers();
|
var currentIndexers = All();
|
||||||
|
|
||||||
foreach (var feedProvider in indexers)
|
foreach (var feedProvider in indexers)
|
||||||
{
|
{
|
||||||
|
@ -166,25 +166,29 @@ private void Execute(Type jobType, int targetId = 0)
|
|||||||
|
|
||||||
var settings = All().Where(j => j.TypeName == jobType.ToString()).FirstOrDefault();
|
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);
|
try
|
||||||
settings.LastExecution = DateTime.Now;
|
|
||||||
var sw = Stopwatch.StartNew();
|
|
||||||
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();
|
||||||
|
|
||||||
_notificationProvider.Register(_notification);
|
_notificationProvider.Register(_notification);
|
||||||
timerClass.Start(_notification, targetId);
|
timerClass.Start(_notification, targetId);
|
||||||
_notification.Status = ProgressNotificationStatus.Completed;
|
_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);
|
SaveSettings(settings);
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Model.Notification;
|
using NzbDrone.Core.Model.Notification;
|
||||||
|
using NzbDrone.Core.Providers.Indexer;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers.Jobs
|
namespace NzbDrone.Core.Providers.Jobs
|
||||||
{
|
{
|
||||||
public class RssSyncJob : IJob
|
public class RssSyncJob : IJob
|
||||||
{
|
{
|
||||||
private readonly IndexerProvider _indexerProvider;
|
private readonly IEnumerable<IndexerProviderBase> _indexers;
|
||||||
|
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public RssSyncJob(IndexerProvider indexerProvider)
|
public RssSyncJob(IEnumerable<IndexerProviderBase> indexers)
|
||||||
{
|
{
|
||||||
_indexerProvider = indexerProvider;
|
_indexers = indexers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
@ -27,13 +30,9 @@ public int DefaultInterval
|
|||||||
|
|
||||||
public void Start(ProgressNotification notification, int targetId)
|
public void Start(ProgressNotification notification, int targetId)
|
||||||
{
|
{
|
||||||
Logger.Info("Doing Things!!!!");
|
foreach (var indexer in _indexers)
|
||||||
|
|
||||||
var indexers = _indexerProvider.AllIndexers().Where(c => c.Enable);
|
|
||||||
|
|
||||||
foreach (var indexerSetting 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
34
NzbDrone.Web/Controllers/SystemController.cs
Normal file
34
NzbDrone.Web/Controllers/SystemController.cs
Normal file
@ -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\SeriesController.cs" />
|
||||||
<Compile Include="Controllers\SettingsController.cs" />
|
<Compile Include="Controllers\SettingsController.cs" />
|
||||||
<Compile Include="Controllers\SharedController.cs" />
|
<Compile Include="Controllers\SharedController.cs" />
|
||||||
<Compile Include="Controllers\JobController.cs" />
|
<Compile Include="Controllers\SystemController.cs" />
|
||||||
<Compile Include="Controllers\UpcomingController.cs" />
|
<Compile Include="Controllers\UpcomingController.cs" />
|
||||||
<Compile Include="Global.asax.cs">
|
<Compile Include="Global.asax.cs">
|
||||||
<DependentUpon>Global.asax</DependentUpon>
|
<DependentUpon>Global.asax</DependentUpon>
|
||||||
@ -660,7 +660,7 @@
|
|||||||
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
|
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
|
||||||
<Content Include="Views\Web.config" />
|
<Content Include="Views\Web.config" />
|
||||||
<Content Include="Views\Settings\Indexers.cshtml" />
|
<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\Downloads.cshtml" />
|
||||||
<Content Include="Views\Settings\EpisodeSorting.cshtml" />
|
<Content Include="Views\Settings\EpisodeSorting.cshtml" />
|
||||||
<Content Include="Views\Settings\General.cshtml" />
|
<Content Include="Views\Settings\General.cshtml" />
|
||||||
@ -673,7 +673,7 @@
|
|||||||
<Content Include="Views\Settings\Index.cshtml" />
|
<Content Include="Views\Settings\Index.cshtml" />
|
||||||
<Content Include="Views\_ViewStart.cshtml" />
|
<Content Include="Views\_ViewStart.cshtml" />
|
||||||
<Content Include="Views\History\Index.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\Upcoming\Index.cshtml" />
|
||||||
<Content Include="Views\Series\Details.cshtml" />
|
<Content Include="Views\Series\Details.cshtml" />
|
||||||
<Content Include="Views\Series\Edit.cshtml" />
|
<Content Include="Views\Series\Edit.cshtml" />
|
||||||
@ -682,6 +682,7 @@
|
|||||||
<Content Include="Views\Series\SeriesSearchResults.cshtml" />
|
<Content Include="Views\Series\SeriesSearchResults.cshtml" />
|
||||||
<Content Include="Views\Shared\Error.cshtml" />
|
<Content Include="Views\Shared\Error.cshtml" />
|
||||||
<Content Include="Views\Settings\UserProfileSection.cshtml" />
|
<Content Include="Views\Settings\UserProfileSection.cshtml" />
|
||||||
|
<Content Include="Views\System\Indexers.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
9
NzbDrone.Web/Views/System/Indexers.cshtml
Normal file
9
NzbDrone.Web/Views/System/Indexers.cshtml
Normal file
@ -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
Block a user