在 Spring Retryable 中的所有尝试之前退出

huangapple go评论61阅读模式
英文:

Exit before all attempts in Spring Retryable

问题

我已经在Spring Boot中编写了一个可重试的部分。它将重试5次,并且重试间隔为5秒。如果满足某个条件,我还想在进行5次迭代之前退出。就像这样:

@Retryable(value = {SomeException.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000))
public void checkForProcessed() throws SomeException {
    if (someCondition) {
        // 在重试5次之前退出可重试逻辑。
    }
}

所以假设在第三次迭代中满足了条件,它不应再重试2次,而应在第三次迭代中退出。

英文:

I have written a Retryable in Spring boot. It will retry 5 times, and with a backoff of 5 seconds. I would also like to exit before 5 iterations, if some condition is met. It's like

    @Retryable(value = {SomeException.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000))
    public void checkForProcessed() throws SomeException {
             if(someCondition) {
    //come out of the retryable before retrying for 5 times.

                }
    }

So let's say the condition is met in the third iteration, it should not retry for 2 more times, and should exit in the 3rd iteration itself

答案1

得分: 0

抛出 SomeOtherException(不可重试的异常)。

英文:

Throw SomeOtherException (which is not retryable).

huangapple
  • 本文由 发表于 2020年9月14日 18:04:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63882173.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定