-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement retry with backoff to help dodge the 501 error #44
Conversation
…opment server as noted in issue#33. Also retries for all other errors. NOT a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Great job figuring this out!
|
||
/** | ||
* Upon failure, retry a function that returns a Promise up to a set number of times, | ||
* with an exponentially increasing delay after each failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, you're doubling the delay each time.
*/ | ||
function backoff(tries, fn, delay = 500) { | ||
return fn().catch(error => { | ||
if (tries > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good for this PR, but a slightly more sophisticated approach would be to check what type of error you're getting. If you know it's the intermittent kind, you could do the backoff, whereas if you know it's something that's never going to work no matter how many times you try, you could just stop.
}) | ||
.catch(error => console.error(error.message)); | ||
}); | ||
backoff(3, fn).catch(error => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, has this shown to work for you in your dev server?
on the development server as noted in issue#33. Also retries for all other errors. NOT a solution.