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

Support Cancelling Retries #46

Open
rgmz opened this issue May 18, 2020 · 1 comment
Open

Support Cancelling Retries #46

rgmz opened this issue May 18, 2020 · 1 comment

Comments

@rgmz
Copy link

rgmz commented May 18, 2020

Describe the feature

Presently, the retryPolicy method specifies how often the circuit breaker should try before failing; however, in certain cases (e.g. expected failures) it is not desirable to continue retrying.

(If this feature exists, I couldn't find any mention of this in the documentation.)

Use cases

Something like a retryOrCancelPolicy would be desirable, where returning -1L would cease the circuit breaker from retrying:

CircuitBreaker.create("my-circuit-breaker", vertx)
    .retryOrCancelPolicy { retryCount: Int, cause: Throwable? ->
       if (cause is MyExpectedException) {
          -1L
       } else {
         retryCount * 1000L
       }
    }

I tend to use michaelbull/kotlin-retry for retrying, which has a pretty elegant way of handling retry policies.

For example:

val retryTimeouts: RetryPolicy<Throwable> = {
    if (reason is SQLDataException) ContinueRetrying else StopRetrying
}

suspend fun printExchangeBetween(a: Long, b: Long) {
  val customer1 = customers.nameFromId(a)
  val customer2 = customers.nameFromId(b)
  println("$customer1 exchanged with $customer2")
}

fun main() = runBlocking {
    retry(retryTimeouts + limitAttempts(5) + constantDelay(20)) {
        printExchangeBetween(1L, 2L)
    }
}

Contribution

I will try to realize this if I get the time; right now I'm holed up with my work laptop, which does not allow me to push externally... even posting this issue was a pain. :|

@vietj
Copy link
Contributor

vietj commented May 18, 2020

@rgmz that would be a great contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants