Failed downloads are added to history

This commit is contained in:
Mark McDowall
2013-10-22 00:31:36 -07:00
parent 2e1b921543
commit e64d2f33d6
18 changed files with 444 additions and 19 deletions

View File

@@ -18,9 +18,11 @@ namespace NzbDrone.Core.History
void Trim();
QualityModel GetBestQualityInHistory(int episodeId);
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType);
List<History> Failed();
}
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>, IHandle<DownloadFailedEvent>
{
private readonly IHistoryRepository _historyRepository;
private readonly Logger _logger;
@@ -41,6 +43,16 @@ namespace NzbDrone.Core.History
return _historyRepository.GetPaged(pagingSpec);
}
public List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType)
{
return _historyRepository.BetweenDates(startDate, endDate, eventType);
}
public List<History> Failed()
{
return _historyRepository.Failed();
}
public void Purge()
{
_historyRepository.Purge();
@@ -51,7 +63,7 @@ namespace NzbDrone.Core.History
_historyRepository.Trim();
}
public virtual QualityModel GetBestQualityInHistory(int episodeId)
public QualityModel GetBestQualityInHistory(int episodeId)
{
return _historyRepository.GetBestQualityInHistory(episodeId).OrderByDescending(q => q).FirstOrDefault();
}
@@ -107,5 +119,23 @@ namespace NzbDrone.Core.History
_historyRepository.Insert(history);
}
}
public void Handle(DownloadFailedEvent message)
{
var history = new History
{
EventType = HistoryEventType.DownloadFailed,
Date = DateTime.UtcNow,
Quality = message.Quality,
SourceTitle = message.SourceTitle,
SeriesId = message.Series.Id,
EpisodeId = message.Episode.Id,
};
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClientId", message.DownloadClientId);
_historyRepository.Insert(history);
}
}
}