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

How to implement a cyclic exponential backoff #47

Open
steve-chavez opened this issue Apr 30, 2017 · 1 comment
Open

How to implement a cyclic exponential backoff #47

steve-chavez opened this issue Apr 30, 2017 · 1 comment

Comments

@steve-chavez
Copy link

Right now I'm stuck with the API, I would like to have a function like this:

  cyclicExponentialBackoff :: Int -> Int -> RetryPolicy
  cyclicExponentialBackoff base cap = ... 

That uses exponentialBackoff and once it reaches the cap it starts again from rsIterNumber = 0. Is there someway I could take advantage of the already implemented exponentialBackoff? Any pointers would help, thanks.

@MichaelXavier
Copy link
Contributor

RetryStatus contains, among other things, an rsCumulativeDelay field which you could use for comparison against your cap. Bear in mind though that this number would keep incrementing even after reset so you'd have to modulo the cumulative delay with your cap or something to get the cumulative delay to be within the current reset you're on. If it doesn't divide evenly, modulo may not be correct.

However, you would not be able to actually set rsIterNumber to 0. That is managed by retry and resetting that to 0 wouldn't really be accurate.

You could also do a poor man's version of this and just run exponentialBackoff with limitRetriesByDelay in a loop. This would reset your iter numbers and give you the resetting behavior. However, I strongly recommend you figure out a termination case that you want and roll that into it so you're not retrying forever.

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

No branches or pull requests

2 participants