failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.2k stars 297 forks source link

Best workflow for calling an API #275

Closed stefnats closed 3 years ago

stefnats commented 3 years ago

Hey there,

I'm using failsafe to call an API and do auto-retries on throttle/limit exceptions.

However, i'm using a Executors.newSingleThreadExecutor() in the Failsafe.with(executor).getAsync(this::callTheApi) command.

Now, this is the problem. When i have, let's say 10 calls, and at call 5 the exception is caught, call 6 gets automatically executed without waiting. I'd like to wait (or handle the retrypolicy) until the call was successful and then go ahead. Is it clear what i tried to explain?

Thanks in advance!

jhalterman commented 3 years ago

Sorry for the delay.

I'd like to wait (or handle the retrypolicy) until the call was successful and then go ahead.

To clarify, you'd like to wait until a call is successful before going ahead with a retry? Once a call is successful a retry wouldn't be needed. If you want to delay between retries, you can do that of course. https://jodah.net/failsafe/javadoc/net/jodah/failsafe/RetryPolicy.html#withDelay-java.time.Duration-

jhalterman commented 3 years ago

Closing for now. Please reopen if needed for further discussion.