cb372 / cats-retry

https://cb372.github.io/cats-retry/
Apache License 2.0
276 stars 45 forks source link

Give RetryPolicy access to failure/error #506

Open erikvanoosten opened 1 week ago

erikvanoosten commented 1 week ago

We have use case where we want to retry some errors immediately, other errors cause a regular exponential backoff.

Is there currently a way to do this with cats-retry? If not, could this feature be added?

erikvanoosten commented 1 week ago

Is this a good work-around?

    def shouldRetryImmediately(t: Throwable): Boolean = ???

    effect
      .retryingOnSomeErrors(
        isWorthRetrying = (t: Throwable) => Async[F].pure(shouldRetryImmediately(t)),
        policy = RetryPolicy(_ => Async[F].pure(PolicyDecision.DelayAndRetry(0.millis))),
        onError = logError,
      )
      .retryingOnAllErrors(policy = ???, onError = logError)
      .void