commit
0c71b7c5d0
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class RetrySpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly IHistoryService _historyService;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RetrySpecification(IHistoryService historyService, IConfigService configService, Logger logger)
|
||||
{
|
||||
_historyService = historyService;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string RejectionReason
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Release has been retried too many times";
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
if (!_configService.EnableFailedDownloadHandling)
|
||||
{
|
||||
_logger.Debug("Failed Download Handling is not enabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
var history = _historyService.FindBySourceTitle(subject.Release.Title);
|
||||
|
||||
if (history.Count(h => h.EventType == HistoryEventType.Grabbed &&
|
||||
HasSamePublishedDate(h, subject.Release.PublishDate)) >
|
||||
_configService.BlacklistRetryLimit)
|
||||
{
|
||||
_logger.Debug("Release has been attempted more times than allowed, rejecting");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool HasSamePublishedDate(History.History item, DateTime publishedDate)
|
||||
{
|
||||
DateTime itemsPublishedDate;
|
||||
|
||||
if (!DateTime.TryParse(item.Data.GetValueOrDefault("PublishedDate", null), out itemsPublishedDate)) return true;
|
||||
|
||||
return itemsPublishedDate.AddDays(-2) <= publishedDate && itemsPublishedDate.AddDays(2) >= publishedDate;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
define(
|
||||
[
|
||||
'backgrid',
|
||||
'Shared/FormatHelpers'
|
||||
], function (Backgrid, FormatHelpers) {
|
||||
return Backgrid.Cell.extend({
|
||||
|
||||
className: 'age-cell',
|
||||
|
||||
render: function () {
|
||||
var age = this.model.get('age');
|
||||
var ageHours = this.model.get('ageHours');
|
||||
|
||||
if (age === 0) {
|
||||
this.$el.html('{0} {1}'.format(ageHours.toFixed(1), this.plural(Math.round(ageHours), 'hour')));
|
||||
}
|
||||
|
||||
else {
|
||||
this.$el.html('{0} {1}'.format(age, this.plural(age, 'day')));
|
||||
}
|
||||
|
||||
this.delegateEvents();
|
||||
return this;
|
||||
},
|
||||
|
||||
plural: function (input, unit) {
|
||||
if (input === 1) {
|
||||
return unit;
|
||||
}
|
||||
|
||||
return unit + 's';
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in new issue