safwank / ElixirRetry

Simple Elixir macros for linear retry, exponential backoff and wait with composable delays
Other
441 stars 32 forks source link

define total retry timeout #19

Closed stephanos closed 6 years ago

stephanos commented 6 years ago

In our code we are communicating with an external system that has "good and bad days". When it has a bad day, it will take a very long time to reply (timeout is 45s). Our default strategy is 5 retries with linear backoff, but we know that we won't get a response at all if we already had 2 retries with a total wait time of 90s - there is no need to retry 3 times more.

Would it be possible to add a total retry limit? Something like this maybe:

result = retry with: lin_backoff(500, 2) |> cap(5_000) |> take(5), max_retry: 90_000 do
   ...
end

To solve it ourselves we added a bunch of timings (started_time and elapsed_time) and then need to fake a return :ok when we passed the maximum retry time. Very awkward.

safwank commented 6 years ago

@stephanos OK. I'll add it to the TODO list.

safwank commented 6 years ago

@stephanos I didn't realize that you can actually use expiry/2 to solve your problem. I'm closing this issue for now, but feel free to reopen it if necessary.

stephanos commented 6 years ago

ah, that's true! awesome, thank you!