fix(request-node): Add exponential backoff in fetchAndRetry#1077
Conversation
|
I should have mentioned this: DeWork recognizes branches like I don't want you to change the branch name because that would auto-close the PR. Instead, could you please click the "Submit Work" button on the DeWork task and post the PR link there? |
MantisClone
left a comment
There was a problem hiding this comment.
The request-node supports command-line arguments. Can you please ensure that passing them as command-line args works and add descriptions to the README?
| retryConfig: { | ||
| maxRetries?: number; | ||
| retryDelay?: number; | ||
| exponentialBackoff?: boolean; |
There was a problem hiding this comment.
maybe this boolean is unnecessary? instead we can expose exponentialBackoffDelay and maxExponentialBackoffDelay and have a default value of 0 for exponentialBackoffDelay
Discussed offline, the command-line args don't apply here since this is request client executed code. This implementation is already following precedence of previous config values. |
- To disable exponential backoff, set maxExponentialBackoffDelay = 0
- Also set default exponential backoff delay to 0
|
@mliu I implemented the exponential backoff configuration parameters but wasn't able to push them to your fork so I pushed them to an upstream branch instead: master...dw-99-exponential-backoffs-in-retry I think this feature may warrant a new test or two in https://github.com/RequestNetwork/requestNetwork/blob/dw-99-exponential-backoffs-in-retry/packages/utils/test/retry.test.ts |
|
Thanks! Added tests |
| // Should call immediately | ||
| expect(throwFn).toHaveBeenCalledTimes(1); | ||
|
|
||
| // Exponential backoff should only call a second time after 2000ms |
There was a problem hiding this comment.
This makes me realize that if you want to have back off like: 1 second, 2 seconds, 4 seconds, 8 seconds, then you need to set the exponentialBackoffDelay to 500 ms.
Closes #1076
Closes dw-99
This PR introduces an
exponentialBackoffoptional flag tofetchAndRetrycalls that increases the time between retried http requests at an exponential rate. These rates are further configurable by setting parameters inretry.tsbut defaults to an exponential growth rate of 2 and a max cap of 30 seconds (i.e. 2, 4, 8, 16, 30). Existing logic like base delay between retries and maximum retries allowed are still preserved.