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

Add multi-policies for retries #55

Open
rucek opened this issue Dec 4, 2023 · 0 comments
Open

Add multi-policies for retries #55

rucek opened this issue Dec 4, 2023 · 0 comments
Labels
enhancement New feature or request retries

Comments

@rucek
Copy link
Contributor

rucek commented Dec 4, 2023

The current retry mechanism only supports a single retry policy for a successful/erroneous result of a given operation, which can only be customized by providing a ResultPolicy that allows for re-defining success or failing fast on given errors. The limitation of this approach is that it doesn't support different retry strategies for different types of errors.

We'd like to be able to define a multi-policy, i.e. one that assigns different retry strategies to different errors, so that e.g. we retry immediately for some errors, but use exponential backoff for others.

A multi-policy could be thought of as a total function E => RetryPolicy, where E is the error type for the operation, e.g.

sealed trait Error

object Error:
  case class WithCode(code: Int) extends Error
  case object Other extends Error

val policy = MultiPolicy {
  case Error.WithCode(code) if code == 42 => RetryPolicy.immediate(3)
  case Error.WithCode(_) => RetryPolicy.delay(4, 1.second)
  case Other => RetryPolicy.backoff(5, 100.millis)
}

One thing to consider is whether we want a notion of "failing fast" within the multi-policy - since it can already be handled by a ResultPolicy(isWorthRetrying = _ => false). Allowing to define it within a multi-policy as well - although possibly useful - might introduce ambiguity.

@rucek rucek added enhancement New feature or request retries labels Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request retries
Projects
None yet
Development

No branches or pull requests

1 participant