Added RecentBacklogSearchJob to fill missing episodes from the last 30 days, runs nightly.

pull/4/head
Mark McDowall 13 years ago
parent 04c71ff64c
commit e781501021

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
public class RecentBacklogSearchJobTest : CoreTest
{
[SetUp]
public void Setup()
{
}
[Test]
public void no_missing_epsiodes_should_not_trigger_any_search()
{
//Setup
var episodes = new List<Episode>();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
//Act
Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, 0, 0);
//Assert
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(MockNotification, It.IsAny<int>(), 0),
Times.Never());
}
[Test]
public void should_only_process_missing_episodes_from_the_last_30_days()
{
//Setup
var episodes = Builder<Episode>.CreateListOfSize(50)
.TheFirst(5)
.With(e => e.AirDate = DateTime.Today)
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-1)) //Today
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-5)) //Yeserday
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-10))
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-15))
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-20))
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-25))
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-30))
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-31)) //31 Days
.TheNext(5)
.With(e => e.AirDate = DateTime.Today.AddDays(-35))
.Build();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<EpisodeSearchJob>().Setup(c => c.Start(It.IsAny<ProgressNotification>(), It.IsAny<int>(), 0));
//Act
Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, 0, 0);
//Assert
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(It.IsAny<ProgressNotification>(), It.IsAny<int>(), 0),
Times.Exactly(40));
}
}
}

@ -96,6 +96,7 @@
<ItemGroup>
<Compile Include="JobTests\BacklogSearchJobTest.cs" />
<Compile Include="JobTests\BannerDownloadJobTest.cs" />
<Compile Include="JobTests\RecentBacklogSearchJobTest.cs" />
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
<Compile Include="ProviderTests\SearchProviderTests\PerformSearchFixture.cs" />
<Compile Include="ProviderTests\SearchProviderTests\ProcessSearchResultsFixture.cs" />

@ -95,6 +95,7 @@ namespace NzbDrone.Core
Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
Kernel.Bind<IJob>().To<AppUpdateJob>().InSingletonScope();
Kernel.Bind<IJob>().To<TrimLogsJob>().InSingletonScope();
Kernel.Bind<IJob>().To<RecentBacklogSearchJob>().InSingletonScope();
Kernel.Get<JobProvider>().Initialize();
Kernel.Get<WebTimer>().StartTimer(30);

@ -235,6 +235,7 @@
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
<Compile Include="Providers\Converting\HandbrakeProvider.cs" />
<Compile Include="Providers\Indexer\Newznab.cs" />
<Compile Include="Providers\Jobs\RecentBacklogSearchJob.cs" />
<Compile Include="Providers\Jobs\TrimLogsJob.cs" />
<Compile Include="Providers\NewznzbProvider.cs" />
<Compile Include="Providers\ExternalNotification\Prowl.cs" />

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Model.Search;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers.Jobs
{
public class RecentBacklogSearchJob : IJob
{
private readonly EpisodeProvider _episodeProvider;
private readonly EpisodeSearchJob _episodeSearchJob;
private readonly SeasonSearchJob _seasonSearchJob;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public RecentBacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob,
SeasonSearchJob seasonSearchJob)
{
_episodeProvider = episodeProvider;
_episodeSearchJob = episodeSearchJob;
_seasonSearchJob = seasonSearchJob;
}
public string Name
{
get { return "Recent Backlog Search"; }
}
public int DefaultInterval
{
get { return 1440; }
}
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{
//Get episodes that are considered missing and aired in the last 30 days
var missingEpisodes = _episodeProvider.EpisodesWithoutFiles(true).Where(e => e.AirDate >= DateTime.Today.AddDays(-30));
Logger.Debug("Processing missing episodes from the last 30 days");
//Process the list of remaining episodes, 1 by 1
foreach (var episode in missingEpisodes)
{
_episodeSearchJob.Start(notification, episode.EpisodeId, 0);
}
}
}
}
Loading…
Cancel
Save