/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class based on the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="retryingHandler">The callback function that will be invoked whenever a retry condition is encountered.</param> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy HandleWith(this RetryStrategy retryStrategy, EventHandler <RetryingEventArgs> retryingHandler) { Guard.ArgumentNotNull(retryStrategy, nameof(retryStrategy)); Guard.ArgumentNotNull(retryingHandler, nameof(retryingHandler)); return(CreateRetryPolicy(retryStrategy).HandleWith(retryingHandler)); }
public UpdateSessionManagerRetryDecorator(IUpdateSessionManager updateSessionManager, RetryStrategy retryStrategy, ITransientErrorDetectionStrategy errorDetectionStrategy) { _updateSessionManager = updateSessionManager; _retryPolicy = new RetryPolicy(errorDetectionStrategy, retryStrategy); }
/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <typeparam name="TException">The type of the transient exception.</typeparam> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy Catch <TException>( this RetryStrategy retryStrategy, Func <TException, bool>?isTransient = null) where TException : Exception => CreateRetryPolicy( Argument.NotNull(retryStrategy, nameof(retryStrategy)), isTransient is null ? exception => exception is TException : exception => exception is TException specifiedException && isTransient(specifiedException));
/// <summary> /// Repetitively executes the specified action while it satisfies the specified retry strategy. /// </summary> /// <param name="action">A delegate that represents the executable action that doesn't return any results.</param> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <param name="retryingHandler">The callback function that will be invoked whenever a retry condition is encountered.</param> /// <exception cref="ArgumentNullException">action</exception> public static void Execute( Action action, RetryStrategy retryStrategy = null, Func <Exception, bool> isTransient = null, EventHandler <RetryingEventArgs> retryingHandler = null) { Guard.ArgumentNotNull(action, nameof(action)); CreateRetryPolicy(retryStrategy, isTransient, retryingHandler).ExecuteAction(action); }
/// <summary> /// Repeatedly executes the specified asynchronous function while it satisfies the current retry policy. /// </summary> /// <param name="func">A asynchronous function that returns a started task (also known as "hot" task).</param> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <param name="retryingHandler">The callback function that will be invoked whenever a retry condition is encountered.</param> /// <returns>Returns a task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will transition to a faulted state and the exception must be observed.</returns> /// <exception cref="ArgumentNullException">func</exception> public static Task ExecuteAsync( Func <Task> func, RetryStrategy retryStrategy = null, Func <Exception, bool> isTransient = null, EventHandler <RetryingEventArgs> retryingHandler = null) { Guard.ArgumentNotNull(func, nameof(func)); return(CreateRetryPolicy(retryStrategy, isTransient, retryingHandler).ExecuteAsync(func)); }
/// <summary> /// Initializes a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified number of retry attempts and parameters defining the progressive delay between retries. /// </summary> /// <param name="errorDetectionStrategy">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.ITransientErrorDetectionStrategy" /> that is responsible for detecting transient conditions.</param> /// <param name="retryStrategy">The strategy to use for this retry policy.</param> public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, RetryStrategy retryStrategy) { Guard.ArgumentNotNull(errorDetectionStrategy, "errorDetectionStrategy"); Guard.ArgumentNotNull(retryStrategy, "retryPolicy"); this.ErrorDetectionStrategy = errorDetectionStrategy; if (errorDetectionStrategy == null) { throw new InvalidOperationException("The error detection strategy type must implement the ITransientErrorDetectionStrategy interface."); } this.RetryStrategy = retryStrategy; }
/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <typeparam name="TException">The type of the transient exception.</typeparam> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy Catch <TException>( this RetryStrategy retryStrategy, Func <TException, bool> isTransient = null) where TException : Exception { Guard.ArgumentNotNull(retryStrategy, nameof(retryStrategy)); return(CreateRetryPolicy( retryStrategy, isTransient == null ? new Func <Exception, bool>(exception => exception is TException) : exception => exception is TException specifiedException && isTransient(specifiedException))); }
/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <param name="retryingHandler">The callback function that will be invoked whenever a retry condition is encountered.</param> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified number of retry attempts and parameters defining the progressive delay between retries.</returns> public static RetryPolicy CreateRetryPolicy( RetryStrategy retryStrategy = null, Func <Exception, bool> isTransient = null, EventHandler <RetryingEventArgs> retryingHandler = null) { RetryPolicy retryPolicy = new RetryPolicy( new ExceptionDetection(isTransient), retryStrategy ?? RetryStrategy.NoRetry); if (retryingHandler != null) { retryPolicy.Retrying += retryingHandler; } return(retryPolicy); }
protected override void Arrange() { this.defaultStrategy = new FixedInterval("default", 5, TimeSpan.FromMilliseconds(10)); this.otherStrategy = new Incremental("other", 5, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); this.defaultSqlConnectionStrategy = new FixedInterval("defaultSqlConnection", 5, TimeSpan.FromMilliseconds(10)); this.defaultSqlCommandStrategy = new FixedInterval("defaultSqlCommand", 5, TimeSpan.FromMilliseconds(10)); this.defaultAzureServiceBusStrategy = new FixedInterval("defaultAzureServiceBusStrategy", 5, TimeSpan.FromMilliseconds(10)); this.defaultAzureCachingStrategy = new FixedInterval("defaultAzureCachingStrategy", 5, TimeSpan.FromMilliseconds(10)); this.defaultAzureStorageStrategy = new FixedInterval("defaultAzureStorageStrategy", 5, TimeSpan.FromMilliseconds(10)); this.managerWithAllDefaults = new RetryManager( new[] { this.defaultStrategy, this.defaultSqlConnectionStrategy, this.defaultSqlCommandStrategy, this.otherStrategy, this.defaultAzureServiceBusStrategy, this.defaultAzureCachingStrategy, this.defaultAzureStorageStrategy }, "default", new Dictionary<string, string> { { "SQL", "defaultSqlCommand" }, { "SQLConnection", "defaultSqlConnection" }, { "ServiceBus", "defaultAzureServiceBusStrategy" }, { "Caching", "defaultAzureCachingStrategy" }, { "WindowsAzure.Storage", "defaultAzureStorageStrategy" }, }); this.managerWithOnlyDefault = new RetryManager( new[] { this.defaultStrategy, this.defaultSqlConnectionStrategy, this.defaultSqlCommandStrategy, this.otherStrategy, this.defaultAzureServiceBusStrategy, this.defaultAzureCachingStrategy, this.defaultAzureStorageStrategy }, "default"); }
protected SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, ISubscriptionReceiverInstrumentation instrumentation, int maxNumberRetry, RetryStrategy backgroundRetryStrategy) { this.settings = settings; this.topic = topic; this.subscription = subscription; this.processInParallel = processInParallel; this.instrumentation = instrumentation; var messagingFactory = MessagingFactory.CreateFromConnectionString(this.settings.ConnectionString); this.client = messagingFactory.CreateSubscriptionClient(topic, subscription); if (this.processInParallel) { this.client.PrefetchCount = 500; } else { this.client.PrefetchCount = 100; } this.dynamicThrottling = new DynamicThrottling( maxDegreeOfParallelism: 10000, minDegreeOfParallelism: 50, penaltyAmount: 3, workFailedPenaltyAmount: 5, workCompletedParallelismGain: 1, intervalForRestoringDegreeOfParallelism: 8000); this.retryStrategy = backgroundRetryStrategy; this.maxNumberRetry = maxNumberRetry; this.receiveRetryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(backgroundRetryStrategy); this.receiveRetryPolicy.Retrying += (s, e) => { this.dynamicThrottling.Penalize(); Trace.TraceWarning( "An error occurred in attempt number {1} to receive a message from subscription {2}: {0}", e.LastException.Message, e.CurrentRetryCount, this.subscription); }; }
/// <summary> /// Initializes a new instance of the <see cref="TopicSender"/> class, /// automatically creating the given topic if it does not exist. /// </summary> protected TopicSender(ServiceBusSettings settings, string topic, int maxNumberRetry, RetryStrategy retryStrategy) { this.settings = settings; this.topic = topic; this.retryStrategy = retryStrategy; this.maxNumberRetry = maxNumberRetry; this.messagingFactory = MessagingFactory.CreateFromConnectionString(settings.ConnectionString); this.topicClient = messagingFactory.CreateTopicClient(this.topic); this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(this.retryStrategy); this.retryPolicy.Retrying += (s, e) => { var handler = this.Retrying; if (handler != null) { handler(this, EventArgs.Empty); } Trace.TraceWarning("An error occurred in attempt number {1} to send a message: {0}", e.LastException.Message, e.CurrentRetryCount); }; }
/// <summary> /// Wraps a Transient Fault Handling Application Block retry strategy into a Microsoft.WindowsAzure.StorageClient.RetryPolicy. /// </summary> /// <param name="retryStrategy">The Transient Fault Handling Application Block retry strategy to wrap.</param> /// <returns>Returns a wrapped Transient Fault Handling Application Block retry strategy into a Microsoft.WindowsAzure.StorageClient.RetryPolicy.</returns> public static Microsoft.WindowsAzure.StorageClient.RetryPolicy AsAzureStorageClientRetryPolicy(this RetryStrategy retryStrategy) { if (retryStrategy == null) { throw new ArgumentNullException("retryStrategy"); } return(() => new ShouldRetryWrapper(retryStrategy.GetShouldRetry()).ShouldRetry); }
protected override void Act() { this.retryStrategy = new FixedInterval(5); this.shouldRetry = this.retryStrategy.GetShouldRetry(); }
protected override void Act() { this.retryStrategy = new FixedInterval("name", 5, TimeSpan.FromSeconds(5)); this.shouldRetry = this.retryStrategy.GetShouldRetry(); }
/// <summary> /// Initializes a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy`1" /> class with the specified number of retry attempts and parameters defining the progressive delay between retries. /// </summary> /// <param name="retryStrategy">The strategy to use for this retry policy.</param> public RetryPolicy(RetryStrategy retryStrategy) : base(default(T) is null ? Activator.CreateInstance <T>() : default !, retryStrategy) { }
/// <summary> /// Initializes a new instance of the <see cref="T:GlebTeterin.ReliableSql.ReliableSqlConnection"/> class with a connection string and a <see cref="P:GlebTeterin.ReliableSql.AzureSqlStrategy"/>. /// </summary> public ReliableSqlConnection(string connectionString, ITransientErrorDetectionStrategy errorDetectionStrategy, RetryStrategy retryStrategy) : this(connectionString, new SmartRetryPolicy(errorDetectionStrategy, retryStrategy)) { }
protected override void Act() { this.retryStrategy = new Incremental(); this.shouldRetry = this.retryStrategy.GetShouldRetry(); }
/// <summary> /// Initializes a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified number of retry attempts and parameters defining the progressive delay between retries. /// </summary> /// <param name="errorDetectionStrategy">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.ITransientErrorDetectionStrategy" /> that is responsible for detecting transient conditions.</param> /// <param name="retryStrategy">The strategy to use for this retry policy.</param> public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, RetryStrategy retryStrategy) { this.ErrorDetectionStrategy = Argument.NotNull(errorDetectionStrategy, nameof(errorDetectionStrategy)); this.RetryStrategy = Argument.NotNull(retryStrategy, nameof(retryStrategy)); }
protected override void Act() { this.retryStrategy = this.managerWithAllDefaults.GetRetryStrategy(); }
public UpdateBlobFactoryRetryLockDecorator(IUpdateBlobFactory updateBlobFactory, RetryStrategy retryStrategy) { _updateBlobFactory = updateBlobFactory; _retryPolicy = new RetryPolicy(new LockUpdateBlobErrorDetectionStrategy(), retryStrategy); }
protected override void Act() { this.retryStrategy = new Incremental("name", 5, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(2)); this.shouldRetry = this.retryStrategy.GetShouldRetry(); }
/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy Catch(this RetryStrategy retryStrategy, Func <Exception, bool>?isTransient = null) => CreateRetryPolicy(Argument.NotNull(retryStrategy, nameof(retryStrategy)), isTransient);
protected override void Act() { this.retryStrategy = new ExponentialBackoff(); this.shouldRetry = this.retryStrategy.GetShouldRetry(); }
/// <summary> /// Create a retry policy for RavenDB concurrency errors. /// </summary> /// <param name="retryStrategy"> /// An optional retry strategy to use (defaults to 3 retries, incremental back-off). /// </param> /// <returns> /// The retry policy. /// </returns> public static RetryPolicy<RavenConcurrencyErrorDetectionStrategy> Concurrency(RetryStrategy retryStrategy = null) { return new RetryPolicy<RavenConcurrencyErrorDetectionStrategy>(retryStrategy ?? DefaultConcurrencyRetryStrategy); }
protected override void Act() { this.retryStrategy = new ExponentialBackoff("name", 5, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(10)); this.shouldRetry = this.retryStrategy.GetShouldRetry(); }
/// <summary> /// Create a new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class with the specified retry strategy. /// </summary> /// <param name="retryStrategy">The retry strategy.</param> /// <param name="isTransient">The predicate function to detect whether the specified exception is transient.</param> /// <returns>A new instance of the <see cref="T:Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy" /> class.</returns> public static RetryPolicy Catch(this RetryStrategy retryStrategy, Func <Exception, bool> isTransient = null) { Guard.ArgumentNotNull(retryStrategy, nameof(retryStrategy)); return(CreateRetryPolicy(retryStrategy, isTransient)); }
/// <summary> /// Initializes a new instance of the <see cref="T:GlebTeterin.ReliableSql.ConnectionManager"/> class with a connection string and a <see cref="P:GlebTeterin.ReliableSql.AzureSqlStrategy"/>. /// </summary> public ConnectionManager(string connectionString, ITransientErrorDetectionStrategy errorDetectionStrategy, RetryStrategy retryStrategy) : this(connectionString, new SmartRetryPolicy(errorDetectionStrategy, retryStrategy)) { }
/// <summary> /// Initializes a new instance of the <see cref="RetryPolicy{T}"/> class with the specified number of retry attempts and parameters defining the progressive delay between retries. /// </summary> /// <param name="retryStrategy">The strategy to use for this retry policy.</param> public RetryPolicy(RetryStrategy retryStrategy) : base(new T(), retryStrategy) { }
public TestExecutor(string connectionString, ITransientErrorDetectionStrategy errorDetectionStrategy, RetryStrategy retryStrategy) { _connectionManager = new ConnectionManager(connectionString, errorDetectionStrategy, retryStrategy); }