Fixed: Do not search for episodes that were just grabbed via RSS Sync

pull/6/head
Mark McDowall 11 years ago
parent 2dbc038d17
commit 017b6ade5e

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common;
@ -13,7 +14,8 @@ namespace NzbDrone.Core.IndexerSearch
{
public interface IEpisodeSearchService
{
void MissingEpisodesAiredAfter(DateTime dateTime);
void MissingEpisodesAiredAfter(DateTime dateTime, IEnumerable<Int32> grabbed
);
}
public class MissingEpisodeSearchService : IEpisodeSearchService, IExecute<EpisodeSearchCommand>, IExecute<MissingEpisodeSearchCommand>
@ -37,11 +39,12 @@ namespace NzbDrone.Core.IndexerSearch
_logger = logger;
}
public void MissingEpisodesAiredAfter(DateTime dateTime)
public void MissingEpisodesAiredAfter(DateTime dateTime, IEnumerable<Int32> grabbed)
{
var missing = _episodeService.EpisodesBetweenDates(dateTime, DateTime.UtcNow)
.Where(e => !e.HasFile &&
!_queueService.GetQueue().Select(q => q.Episode.Id).Contains(e.Id))
!_queueService.GetQueue().Select(q => q.Episode.Id).Contains(e.Id) &&
!grabbed.Contains(e.Id))
.ToList();
var downloadedCount = 0;

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Download;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Instrumentation.Extensions;
@ -11,7 +13,7 @@ namespace NzbDrone.Core.Indexers
{
public interface IRssSyncService
{
void Sync();
List<DownloadDecision> Sync();
}
public class RssSyncService : IRssSyncService, IExecute<RssSyncCommand>
@ -36,7 +38,7 @@ namespace NzbDrone.Core.Indexers
}
public void Sync()
public List<DownloadDecision> Sync()
{
_logger.ProgressInfo("Starting RSS Sync");
@ -45,16 +47,18 @@ namespace NzbDrone.Core.Indexers
var downloaded = _downloadApprovedReports.DownloadApproved(decisions);
_logger.ProgressInfo("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, downloaded.Count());
return downloaded;
}
public void Execute(RssSyncCommand message)
{
Sync();
var downloaded = Sync();
if (message.LastExecutionTime.HasValue && DateTime.UtcNow.Subtract(message.LastExecutionTime.Value).TotalHours > 3)
{
_logger.Info("RSS Sync hasn't run since: {0}. Searching for any missing episodes since then.", message.LastExecutionTime.Value);
_episodeSearchService.MissingEpisodesAiredAfter(message.LastExecutionTime.Value.AddDays(-1));
_episodeSearchService.MissingEpisodesAiredAfter(message.LastExecutionTime.Value.AddDays(-1), downloaded.SelectMany(d => d.RemoteEpisode.Episodes).Select(e => e.Id));
}
}
}

Loading…
Cancel
Save