Интересно в c# посмотреть на реализацию сложного ретрая
например. Докинуть задержку ретрая не сложно, если что. Что-то ещё не покроет?
readonly struct RetryPolicy
{
public static RetryPolicy Default => new RetryPolicy(_ => false, maxAttempts: 3);
//ctor goes here
private readonly Func<Exception, bool> _condition;
private readonly int _maxAttempts;
public RetryPolicy WithMaxAttempts(int maxAttempts)
=> new RetryPolicy(_condition, maxAttempts);
public RetryPolicy When(Func<Exception, bool> condition)
=> new RetyPolicy(e => _condition(e) || condition(e), _maxAttempts);
//shugar for typed exceptions handling goes here
// basic async overload
public async Task<TOut> ExecuteAsync<TContext, TOut>(TContext context, Func<TContext, Task<TOut>> retryable)
{
var result = default(TOut);
var attemptsLeft = _maxAttempts;
while (attemptsLeft > 0)
try
{
result = await retryable(context).ConfigureAwait(false);
}
catch (Exception e) when (_condition(e))
{
attemptsLeft--;
}
return result;
}
}