safwank/ElixirRetry

define total retry timeout

stephanos opened this issue · 3 comments

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.

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

@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.

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