using System; using Polly; using Serilog; namespace SyncEngine.Sync { public static class BatchProcessor { public static void ExecuteWithRetry(Action action, int maxRetries, ILogger logger, string context) { Policy.Handle() .WaitAndRetry( maxRetries, attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)), (ex, span, attempt, ctx) => { logger.Warning(ex, "Retry {Attempt}/{Max} for {Context} after {Delay}s", attempt, maxRetries, context, span.TotalSeconds); }) .Execute(action); } public static T ExecuteWithRetry(Func func, int maxRetries, ILogger logger, string context) { return Policy.Handle() .WaitAndRetry( maxRetries, attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)), (ex, span, attempt, ctx) => { logger.Warning(ex, "Retry {Attempt}/{Max} for {Context} after {Delay}s", attempt, maxRetries, context, span.TotalSeconds); }) .Execute(func); } } }