From 18e94385d85663e84236a5be2a76de16f57f291b Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 8 Aug 2023 15:04:17 +0100 Subject: [PATCH] Fix samples React to breaking changes. --- samples/Extensibility/Program.cs | 6 +++--- samples/GenericStrategies/Program.cs | 2 +- samples/Intro/Program.cs | 6 +++--- samples/Retries/Program.cs | 13 +++++++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/samples/Extensibility/Program.cs b/samples/Extensibility/Program.cs index c9e27adfba9..7a86595da2b 100644 --- a/samples/Extensibility/Program.cs +++ b/samples/Extensibility/Program.cs @@ -4,7 +4,7 @@ // ------------------------------------------------------------------------ // Usage of custom strategy // ------------------------------------------------------------------------ -var strategy = new ResilienceStrategyBuilder() +var strategy = new CompositeStrategyBuilder() // This is custom extension defined in this sample .AddMyResilienceStrategy(new MyResilienceStrategyOptions { @@ -23,7 +23,7 @@ // SIMPLE EXTENSIBILITY MODEL (INLINE STRATEGY) // ------------------------------------------------------------------------ -strategy = new ResilienceStrategyBuilder() +strategy = new CompositeStrategyBuilder() // Just add the strategy instance directly .AddStrategy(new MySimpleStrategy()) .Build(); @@ -125,7 +125,7 @@ protected override async ValueTask> ExecuteCore" - public static TBuilder AddMyResilienceStrategy(this TBuilder builder, MyResilienceStrategyOptions options) where TBuilder : ResilienceStrategyBuilderBase + public static TBuilder AddMyResilienceStrategy(this TBuilder builder, MyResilienceStrategyOptions options) where TBuilder : CompositeStrategyBuilderBase => builder.AddStrategy( // Provide a factory that creates the strategy context => new MyResilienceStrategy(context.Telemetry, options), diff --git a/samples/GenericStrategies/Program.cs b/samples/GenericStrategies/Program.cs index 3904090f42f..51e8e1294cc 100644 --- a/samples/GenericStrategies/Program.cs +++ b/samples/GenericStrategies/Program.cs @@ -11,7 +11,7 @@ // The generic ResilienceStrategyBuilder creates a ResilienceStrategy // that can execute synchronous and asynchronous callbacks that return T. -ResilienceStrategy strategy = new ResilienceStrategyBuilder() +ResilienceStrategy strategy = new CompositeStrategyBuilder() .AddFallback(new FallbackStrategyOptions { FallbackAction = _ => diff --git a/samples/Intro/Program.cs b/samples/Intro/Program.cs index 9271bcea4af..891e955151e 100644 --- a/samples/Intro/Program.cs +++ b/samples/Intro/Program.cs @@ -9,7 +9,7 @@ // The ResilienceStrategyBuilder creates a ResilienceStrategy // that can be executed synchronously or asynchronously // and for both void and result-returning user-callbacks. -ResilienceStrategy strategy = new ResilienceStrategyBuilder() +ResilienceStrategy strategy = new CompositeStrategyBuilder() // Use convenience extension that accepts TimeSpan .AddTimeout(TimeSpan.FromSeconds(5)) .Build(); @@ -37,7 +37,7 @@ // 3. Create and execute a pipeline of strategies // ------------------------------------------------------------------------ -strategy = new ResilienceStrategyBuilder() +strategy = new CompositeStrategyBuilder() // Add retries using the options .AddRetry(new RetryStrategyOptions { @@ -51,7 +51,7 @@ _ => PredicateResult.False }, // Register user callback called whenever retry occurs - OnRetry = args => { Console.WriteLine($"Retrying...{args.Arguments.Attempt} attempt"); return default; }, + OnRetry = args => { Console.WriteLine($"Retrying...{args.Arguments.AttemptNumber} attempt"); return default; }, BaseDelay = TimeSpan.FromMilliseconds(400), BackoffType = RetryBackoffType.Constant, RetryCount = 3 diff --git a/samples/Retries/Program.cs b/samples/Retries/Program.cs index 45a0a5eda53..46a922ad714 100644 --- a/samples/Retries/Program.cs +++ b/samples/Retries/Program.cs @@ -9,7 +9,7 @@ // 1. Create a retry strategy that handles all exceptions // ------------------------------------------------------------------------ -ResilienceStrategy strategy = new ResilienceStrategyBuilder() +ResilienceStrategy strategy = new CompositeStrategyBuilder() // Default retry options handle all exceptions .AddRetry(new RetryStrategyOptions()) .Build(); @@ -21,7 +21,7 @@ // 2. Customize the retry behavior // ------------------------------------------------------------------------ -strategy = new ResilienceStrategyBuilder() +strategy = new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { // Specify what exceptions should be retried using PredicateBuilder @@ -31,7 +31,8 @@ // The recommended backoff type for HTTP scenarios // See here for more information: https://github.com/App-vNext/Polly/wiki/Retry-with-jitter#more-complex-jitter - BackoffType = RetryBackoffType.ExponentialWithJitter + BackoffType = RetryBackoffType.Exponential, + UseJitter = true }) .Build(); @@ -42,7 +43,7 @@ // 3. Register the callbacks // ------------------------------------------------------------------------ -strategy = new ResilienceStrategyBuilder() +strategy = new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { // Specify what exceptions should be retried using switch expressions @@ -53,7 +54,7 @@ }, OnRetry = outcome => { - Console.WriteLine($"Retrying attempt {outcome.Arguments.Attempt}..."); + Console.WriteLine($"Retrying attempt {outcome.Arguments.AttemptNumber}..."); return default; } }) @@ -66,7 +67,7 @@ // 4. Create an HTTP retry strategy that handles both exceptions and results // ------------------------------------------------------------------------ -ResilienceStrategy httpStrategy = new ResilienceStrategyBuilder() +ResilienceStrategy httpStrategy = new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { // Specify what exceptions or results should be retried