mirror of
https://github.com/Prowlarr/Prowlarr
synced 2025-12-14 20:43:43 +01:00
Fixed: (Rarbg) Improve RateLimit Handling
Fixed: (Rarbg) Increase delay to 4s to reduce Rate Limiting Fixes #1169
This commit is contained in:
parent
ba3a240707
commit
518c85dee2
2 changed files with 24 additions and 11 deletions
|
|
@ -34,7 +34,7 @@ public class Rarbg : TorrentIndexerBase<RarbgSettings>
|
||||||
|
|
||||||
public override IndexerCapabilities Capabilities => SetCapabilities();
|
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)
|
public Rarbg(IRarbgTokenProvider tokenProvider, IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger)
|
||||||
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
|
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
|
||||||
|
|
@ -106,7 +106,8 @@ protected override async Task<IndexerQueryResult> FetchPage(IndexerRequest reque
|
||||||
{
|
{
|
||||||
var response = await FetchIndexerResponse(request);
|
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);
|
var jsonResponse = new HttpResponse<RarbgResponse>(response.HttpResponse);
|
||||||
|
|
||||||
if (jsonResponse.Resource.error_code.HasValue)
|
if (jsonResponse.Resource.error_code.HasValue)
|
||||||
|
|
@ -123,9 +124,9 @@ protected override async Task<IndexerQueryResult> FetchPage(IndexerRequest reque
|
||||||
request.HttpRequest.Url = request.Url.SetQuery(qs.GetQueryString());
|
request.HttpRequest.Url = request.Url.SetQuery(qs.GetQueryString());
|
||||||
response = await FetchIndexerResponse(request);
|
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);
|
response = await FetchIndexerResponse(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,20 +23,32 @@ public RarbgParser(IndexerCapabilities capabilities)
|
||||||
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
||||||
{
|
{
|
||||||
var results = new List<ReleaseInfo>();
|
var results = new List<ReleaseInfo>();
|
||||||
|
var retryTime = TimeSpan.FromMinutes(1);
|
||||||
|
var responseCode = (int)indexerResponse.HttpResponse.StatusCode;
|
||||||
|
|
||||||
switch (indexerResponse.HttpResponse.StatusCode)
|
switch (responseCode)
|
||||||
{
|
{
|
||||||
default:
|
case (int)HttpStatusCode.TooManyRequests:
|
||||||
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
retryTime = TimeSpan.FromMinutes(2);
|
||||||
{
|
throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, retryTime);
|
||||||
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
|
case 520:
|
||||||
}
|
retryTime = TimeSpan.FromMinutes(3);
|
||||||
|
throw new TooManyRequestsException(indexerResponse.HttpRequest, indexerResponse.HttpResponse, retryTime);
|
||||||
|
case (int)HttpStatusCode.OK:
|
||||||
|
retryTime = TimeSpan.FromMinutes(5);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", responseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonResponse = new HttpResponse<RarbgResponse>(indexerResponse.HttpResponse);
|
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.HasValue)
|
||||||
{
|
{
|
||||||
if (jsonResponse.Resource.error_code == 20 || jsonResponse.Resource.error_code == 8
|
if (jsonResponse.Resource.error_code == 20 || jsonResponse.Resource.error_code == 8
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue