Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate the Timeout Policy #1071

Closed
martintmk opened this issue Mar 20, 2023 · 0 comments · Fixed by #1079
Closed

Migrate the Timeout Policy #1071

martintmk opened this issue Mar 20, 2023 · 0 comments · Fixed by #1079
Labels
v8 Issues related to the new version 8 of the Polly library.
Milestone

Comments

@martintmk
Copy link
Contributor

martintmk commented Mar 20, 2023

Migrate the Timeout Policy to V8 API.

Prerequisites
#1070
#1067

The details on how to introduce the new resilience strategies for V8 are here.

The steps in general:

  • Move exceptions and enums and classes that are shared between V7 and V8 into Polly.Core
  • Use Type Forwarding so the consumers still using V7 won't get runtime errors.
  • Introduce TimeoutOptions
  • Expose new extensions for the timeout strategy.
  • Forward the V7 implementation to V8.

API

public class TimeoutStrategyOptions
{
   public TimeoutStrategy Strategy { get; set; }

   public Event<OnTimeoutArguments> OnTimeout { get; set; }

   public Generator<TimeoutGeneratorArguments, TimeSpan> TimeoutGenerator { get; set; }
}

public readonly struct OnTimeoutArguments
{
   public ResilienceContext ResilienceContext { get; }
   public TimeSpan ExecutionTime { get; }
}

public readonly struct TimeoutGeneratorArguments
{
   public ResilienceContext ResilienceContext { get; }
}

public static class TimeoutResilienceStrategyBuilderExtensions
{
   ResilienceStrategyBuilder AddTimeout(this ResilienceStrategyBuilder builder, TimeoutStrategyOptions options);
   ResilienceStrategyBuilder AddTimeout(this ResilienceStrategyBuilder builder, TimeSpan timeout);
   ResilienceStrategyBuilder AddTimeout(this ResilienceStrategyBuilder builder, TimeSpan timeout, TimeoutStrategy  strategy);

   // possibly more
}

API Usage

// advanced setup
var options = new TimeoutStrategyOptions();

// add an event that's called when timeout occurrs
options.OnTimeout.Add(args => Console.WriteLine("Timeout occurred!"))

// add callback to result generator, you can return different timeouts based on the result type or data from resilience context
options.TimeoutGenerator.Add(args => TimeSpan.FromSeconds(5));
var strategy = new ResilienceStrategyBuilder().AddTimeout(options).Build();

// simple setup
var strategy = new ResilienceStrategyBuilder().AddTimeout(TimeSpan.FromSeconds(5)).Build();
@martintmk martintmk added the v8 Issues related to the new version 8 of the Polly library. label Mar 20, 2023
@martintmk martintmk added this to the v8.0.0 milestone Mar 20, 2023
@martintmk martintmk linked a pull request Mar 23, 2023 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues related to the new version 8 of the Polly library.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant