Fixed: (Rarbg) Improve RateLimit Handling

Fixed: (Rarbg) Increase delay to 4s to reduce Rate Limiting

Fixes #1169
pull/1262/head
Bakerboy448 2 years ago committed by Qstick
parent ba3a240707
commit 518c85dee2

@ -34,7 +34,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
public override IndexerCapabilities Capabilities => SetCapabilities();
public override TimeSpan RateLimit => TimeSpan.FromSeconds(2);
public override TimeSpan RateLimit => TimeSpan.FromSeconds(4);
public Rarbg(IRarbgTokenProvider tokenProvider, IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger)
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
@ -106,7 +106,8 @@ namespace NzbDrone.Core.Indexers.Rarbg
{
var response = await FetchIndexerResponse(request);
// try and recover from token or rate limit errors
// try and recover from token errors
// Response of 200 and rate_limt of 1 requires a 5 minute backoff. Handle in Response Parsing & do not page further if rate_limit is populated.
var jsonResponse = new HttpResponse<RarbgResponse>(response.HttpResponse);
if (jsonResponse.Resource.error_code.HasValue)
@ -123,9 +124,9 @@ namespace NzbDrone.Core.Indexers.Rarbg
request.HttpRequest.Url = request.Url.SetQuery(qs.GetQueryString());
response = await FetchIndexerResponse(request);
}
else if (jsonResponse.Resource.error_code == 5 || jsonResponse.Resource.rate_limit.HasValue)
else if (jsonResponse.Resource.error_code == 5)
{
_logger.Debug("Rarbg rate limit hit, retying request");
_logger.Debug("Rarbg temp rate limit hit, retying request");
response = await FetchIndexerResponse(request);
}
}

@ -23,20 +23,32 @@ namespace NzbDrone.Core.Indexers.Rarbg
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
{
var results = new List<ReleaseInfo>();
var retryTime = TimeSpan.FromMinutes(1);
var responseCode = (int)indexerResponse.HttpResponse.StatusCode;
switch (indexerResponse.HttpResponse.StatusCode)
switch (responseCode)
{
default:
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
}
case (int)HttpStatusCode.TooManyRequests:
retryTime = TimeSpan.FromMinutes(2);
throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, retryTime);
case 520:
retryTime = TimeSpan.FromMinutes(3);
throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, retryTime);
case (int)HttpStatusCode.OK:
retryTime = TimeSpan.FromMinutes(5);
break;
default:
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", responseCode);
}
var jsonResponse = new HttpResponse<RarbgResponse>(indexerResponse.HttpResponse);
// Handle 200 Rate Limiting
if (jsonResponse.Resource.rate_limit == 1)
{
throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, retryTime);
}
if (jsonResponse.Resource.error_code.HasValue)
{
if (jsonResponse.Resource.error_code == 20 || jsonResponse.Resource.error_code == 8

Loading…
Cancel
Save