This commit is contained in:
2022-12-16 06:01:23 +00:00
parent 26c2ae5cc9
commit effd96143f
310 changed files with 48715 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Sockeye.Util
{
/// <summary>
/// what it says
/// </summary>
public static class RetryHelper
{
/// <summary>
///
/// </summary>
/// <param name="times"></param>
/// <param name="delay"></param>
/// <param name="log"></param>
/// <param name="logPrepend"></param>
/// <param name="operation"></param>
public static void RetryOnException(int times, TimeSpan delay, ILogger log, string logPrepend, Action operation)
{
var attempts = 0;
do
{
try
{
attempts++;
operation();
break; // Sucess! Lets exit the loop!
}
catch (Exception ex)
{
if (attempts == times)
throw;
log.LogError(ex, $"{logPrepend} Exception caught on attempt {attempts} of {times} - will retry after delay {delay}");
Task.Delay(delay).Wait();
}
} while (true);
}
}
}