-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: allow strategies other than polynomial #412
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,19 @@ export async function errorRequest(state, octokit, error, options) { | |
if (error.status >= 400 && !state.doNotRetry.includes(error.status)) { | ||
const retries = | ||
options.request.retries != null ? options.request.retries : state.retries; | ||
const retryAfter = Math.pow((options.request.retryCount || 0) + 1, 2); | ||
const base = (options.request.retryCount || 0) + 1; | ||
let retryAfter; | ||
switch (state.strategy) { | ||
case "exponential": | ||
retryAfter = Math.pow(2, base); | ||
break; | ||
case "linear": | ||
retryAfter = base; | ||
break; | ||
default: // "polynomial" | ||
retryAfter = Math.pow(base, 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the polynomial strategy, you'll want Also, you might want to wrap this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrapped As mentioned in #412 (comment), I think that would make it exponential backoff. Full disclosure, I named this one polynomial by looking at what others tool call it (e.g. https://backoff-utils.readthedocs.io/en/latest/strategies.html#polynomial). |
||
break; | ||
} | ||
throw octokit.retry.retryRequest(error, retries, retryAfter); | ||
} | ||
|
||
|
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.
You have base inverted with your power - You'll need to do:
Math.pow(base, exp)
.Also, you might want to wrap this in
Math.round(Math.pow(base, exp))
just becausepow
returns a doubleThere 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.
Thanks! I renamed
base
variable toretryCount
so that it's a bit less confusing. I also wrapped it inMath.round
as suggested.It reads as following now:
As for the inversion, as per https://en.wikipedia.org/wiki/Exponential_backoff, exponential backoff is formed by taking the multiplicative factor (in this case 2) to the power of the number of observed events (in this case the number of retries that have already been performed). So I think it is correct now. Let me know if you wanted me to use different names though.