[feature] Indexer status (#11706)

Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
This commit is contained in:
Alessio Gogna
2021-06-24 04:37:27 +02:00
committed by GitHub
parent e1704e6037
commit b9c3f593da
9 changed files with 173 additions and 2 deletions

View File

@@ -36,6 +36,14 @@ namespace Jackett.Common.Indexers
public virtual bool IsConfigured { get; protected set; }
public virtual string[] Tags { get; protected set; }
// https://github.com/Jackett/Jackett/issues/3292#issuecomment-838586679
private TimeSpan HealthyStatusValidity => cacheService.CacheTTL + cacheService.CacheTTL;
private static readonly TimeSpan ErrorStatusValidity = TimeSpan.FromMinutes(10);
private static readonly TimeSpan MaxStatusValidity = TimeSpan.FromDays(1);
private int errorCount;
private DateTime expireAt;
protected Logger logger;
protected IIndexerConfigurationService configurationService;
protected IProtectionService protectionService;
@@ -61,6 +69,10 @@ namespace Jackett.Common.Indexers
}
}
public virtual bool IsHealthy => errorCount == 0 && expireAt > DateTime.Now;
public virtual bool IsFailing => errorCount > 0 && expireAt > DateTime.Now;
public abstract TorznabCapabilities TorznabCaps { get; protected set; }
// standard constructor used by most indexers
@@ -92,6 +104,8 @@ namespace Jackett.Common.Indexers
{
CookieHeader = string.Empty;
IsConfigured = false;
errorCount = 0;
expireAt = DateTime.MinValue;
}
public virtual void SaveConfig() => configurationService.Save(this as IIndexer, configData.ToJson(protectionService, forDisplay: false));
@@ -386,10 +400,14 @@ namespace Jackett.Common.Indexers
results = FilterResults(query, results);
results = FixResults(query, results);
cacheService.CacheResults(this, query, results.ToList());
errorCount = 0;
expireAt = DateTime.Now.Add(HealthyStatusValidity);
return new IndexerResult(this, results, false);
}
catch (Exception ex)
{
var delay = Math.Min(MaxStatusValidity.TotalSeconds, ErrorStatusValidity.TotalSeconds * Math.Pow(2, errorCount++));
expireAt = DateTime.Now.AddSeconds(delay);
throw new IndexerException(this, ex);
}
}