feat: allow strategies other than polynomial#412
feat: allow strategies other than polynomial#412galargh wants to merge 2 commits intooctokit:mainfrom
Conversation
src/error-request.ts
Outdated
| let retryAfter; | ||
| switch (state.strategy) { | ||
| case "exponential": | ||
| retryAfter = Math.pow(2, base); |
There was a problem hiding this comment.
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 because pow returns a double
There was a problem hiding this comment.
Thanks! I renamed base variable to retryCount so that it's a bit less confusing. I also wrapped it in Math.round as suggested.
It reads as following now:
Math.round(Math.pow(2, retryCount))
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.
src/error-request.ts
Outdated
| retryAfter = base; | ||
| break; | ||
| default: // "polynomial" | ||
| retryAfter = Math.pow(base, 2); |
There was a problem hiding this comment.
For the polynomial strategy, you'll want Math.pow(2, base)
Also, you might want to wrap this in Math.round(Math.pow(base, exp)) just because pow returns a double
There was a problem hiding this comment.
Wrapped Math.pow with Math.round - great spot, thanks 😄
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).
Resolves #ISSUE_NUMBER (not applicable; issue does not exist)
Behavior
Before the change?
RETRY_AFTER_BASE * (RETRY_COUNT + 1)^2)After the change?
strategyas an option.exponential(RETRY_AFTER_BASE * 2^(RETRY_COUNT + 1))linear(RETRY_AFTER_BASE * (RETRY_COUNT + 1))polynomial(RETRY_AFTER_BASE * (RETRY_COUNT + 1)^2)polynomialstrategy (backwards compatible).Other information
Additional info
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!
Type: Breaking changelabel)If
Yes, what's the impact:Pull request type
Type: Feature