2011-11-24 02:09:09 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-01-15 01:01:51 +01:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
|
2011-12-02 02:33:17 +01:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
|
|
|
|
public class RecentBacklogSearchJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
|
|
|
|
private readonly EpisodeSearchJob _episodeSearchJob;
|
2012-01-15 01:01:51 +01:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2012-01-15 01:01:51 +01:00
|
|
|
|
public RecentBacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob,
|
|
|
|
|
ConfigProvider configProvider)
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
|
|
|
|
_episodeProvider = episodeProvider;
|
|
|
|
|
_episodeSearchJob = episodeSearchJob;
|
2012-01-15 01:01:51 +01:00
|
|
|
|
_configProvider = configProvider;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Recent Backlog Search"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 03:47:23 +01:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
2012-01-15 03:47:23 +01:00
|
|
|
|
get { return TimeSpan.FromDays(1); }
|
2011-11-24 02:09:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
|
|
|
|
{
|
2012-01-15 01:01:51 +01:00
|
|
|
|
if (!_configProvider.EnableBacklogSearching)
|
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Backlog searching is not enabled, aborting job.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-24 02:09:09 +01:00
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|