Skip to content

Commit

Permalink
Add delay between retry attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
6cUbi57z committed Mar 14, 2021
1 parent 52f085f commit 0cfb82f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Jackett.Common/Indexers/Anidex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ public class Anidex : BaseWebIndexer
{"2", "2 attempts"},
{"3", "3 attempts"},
{"4", "4 attempts"},
{"5", "5 attempts"},
{"6", "6 attempts"},
{"7", "7 attempts"},
{"8", "8 attempts"},
{"9", "9 attempts"},
{"10", "10 attempts"}
{"5", "5 attempts"}
})
{
Name = "Number of attempts",
Expand Down Expand Up @@ -204,13 +199,16 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
catString = "&id=" + string.Join(",", searchCategories);

// Configure the retry policy
int attemptNumber = 1;
var retryPolicy = Policy
.HandleResult<WebResult>(r => (int)r.Status >= 500)
.RetryAsync(
.WaitAndRetryAsync(
NumberOfAttempts - 1,
onRetry: (exception, retryCount, context) =>
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt) / 2),
onRetry: (exception, timeSpan, context) =>
{
logger.Warn($"Request to Anidex failed with status {exception.Result.Status} (Attempt {retryCount} of {NumberOfAttempts}).");
logger.Warn($"Request to Anidex failed with status {exception.Result.Status}. Retrying in {timeSpan.TotalSeconds}s... (Attempt {attemptNumber} of {NumberOfAttempts}).");
attemptNumber++;
});

var response = await retryPolicy.ExecuteAsync(async () =>
Expand Down

0 comments on commit 0cfb82f

Please sign in to comment.