public static async Task RetryAsync(IDbRetryPolicy policy, Func <Task> action, CancellationToken cancellationToken = default) { if (policy == null) { throw new ArgumentNullException(nameof(policy)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } IEnumerator <TimeSpan> intervals = null; while (true) { try { await action(); return; } catch (Exception ex) when(policy.ShouldRetry(ex)) { if (intervals == null) { intervals = policy.Strategy.GetIntervals().GetEnumerator(); } if (!intervals.MoveNext()) { throw; } await Task.Delay(intervals.Current, cancellationToken); } } }
public static T Retry <T>(IDbRetryPolicy policy, Func <T> action) { if (policy == null) { throw new ArgumentNullException(nameof(policy)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } IEnumerator <TimeSpan> intervals = null; while (true) { try { return(action()); } catch (Exception ex) when(policy.ShouldRetry(ex)) { if (intervals == null) { intervals = policy.Strategy.GetIntervals().GetEnumerator(); } if (!intervals.MoveNext()) { throw; } Thread.Sleep(intervals.Current); } } }
public AzureSqlDbConnectionFactory(string readWriteConnectionString, string readOnlyConnectionString, IDbRetryPolicy dbRetryPolicy, ILogger <AzureSqlDbConnectionFactory>?logger) { if (string.IsNullOrWhiteSpace(readWriteConnectionString)) { throw new ArgumentNullException(nameof(readWriteConnectionString)); } if (string.IsNullOrWhiteSpace(readOnlyConnectionString)) { throw new ArgumentNullException(nameof(readOnlyConnectionString)); } _logger = logger; _readWriteConnectionString = readWriteConnectionString; _readOnlyConnectionString = readOnlyConnectionString; _dbRetryPolicy = dbRetryPolicy; }
public ReliableSqlDbConnection(string connectionString, IDbRetryPolicy retryPolicy) { _connectionString = connectionString; _retryPolicy = retryPolicy; _underlyingConnection = new SqlConnection(connectionString); }
public ReliableSqlDbCommand(SqlCommand command, IDbRetryPolicy retryPolicy) { _underlyingSqlCommand = command; _retryPolicy = retryPolicy; }
public DbConnectionFactory(IConfigurationProvider configurationProvider, IDbRetryPolicy retryPolicy) { _retryPolicy = retryPolicy; _configurationProvider = configurationProvider; }
public DbContextConfiguration(IDbRetryPolicy retryPolicy = null, IsolationLevel?defaultIsolationLevel = null, IDbContextEvents events = null) { RetryPolicy = retryPolicy; DefaultIsolationLevel = defaultIsolationLevel; Events = events; }