coveooss / exponential-backoff Goto Github PK
View Code? Open in Web Editor NEWA utility that allows retrying a function with an exponential delay between attempts.
License: Apache License 2.0
A utility that allows retrying a function with an exponential delay between attempts.
License: Apache License 2.0
Hey ๐
We have a use case where we need to dictate whether to retry
based on the response
from an API call, not the error
from the call.
I want to perform a retry is response.data
is equal to an empty object. E.G {}
. The API won't "error" from this, the response will be a 200
and it has got some data back, the data is just an empty object.
Right now, the retry
function only allows you to access the error
and the number of attempts. In my use case that doesn't quite seem to fit the need ๐ข
Maybe I am missing something in your docs (and I'm sorry if I am), I have done some trial and error locally on my machine, but I can't seem to access the response
in the retry
function.
Have you got an example of this working, if not, is it something you would think about incorporating?
Are there plans to make the retry function an async one returning Promise<boolean>
?
I need to do some async code execution in there (Deleting the currently stored access token if we are getting a not authenticated error).
Thanks for this amazing lib!
Best regards,
Yannick
It's weird that the first argument is not just the function when all other arguments are optional
Move retry function to the second argument (backoff options) and make the first argument the function (preferred)
Or make the only argument an object where the only required key is the fn
key (dislike this because the 'fn' key is not intuitive)
Hello,
the License attached to the project does ot contain any information about the copyright holder(s).
See the last paragraph of the https://github.com/coveooss/exponential-backoff/blob/master/LICENSE
This would help in attributing the module in case it is reused under the license.
Thanks in advance!
Is there any scope for adding functionality for inverse exponential backoff?
A simple DX would be to add a negative integer value to the timeMultiple
, a minDelay
optioion.
There are multiple uses case especially when we use polling APIs to get the result of an async task.
It doesn't make sense increase the wait time exponentially if the task has been finished before the next polling cycle.
Is there any way that we can pass in a function as an option which is called for each retry?
I'm looking to log retry attempts as they happen, preferably with the attempt number included.
Cool. Can you show us how to gradually reverse backoff or restore to original startDelay when a successful endpoint response is received?
When jitter is used the max retry is not infinite
It is often useful to be able to perform some actions before each retry, for example, to log that a retry has occurred.
This can be done by enabling beforeRetry hook, which accepts a function. And before every retry this function is called with the retry number.
Example: https://github.com/sindresorhus/got#hooksbeforeretry
In many (most?) use cases, I think it would make more sense to try to first execution immediately, and then do the delay after executing.
It seems like versions 1.2.0 and 2.0.0 are missing the dist folder in the npm package.
temp $ npm install [email protected]
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 1.945s
found 0 vulnerabilities
temp $ cd node_modules/exponential-backoff/
exponential-backoff $ ls
LICENSE README.md dist package.json
exponential-backoff $ cd ..
node_modules $ cd ..
temp $ rm -rf node_modules/
temp $ npm install [email protected]
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 0.664s
found 0 vulnerabilities
temp $ cd node_modules/exponential-backoff/
exponential-backoff $ ls
LICENSE README.md package.json
exponential-backoff $ cd ..
node_modules $ cd ..
temp $ rm -rf node_modules/
temp $ npm install [email protected]
+ [email protected]
added 1 package from 1 contributor and audited 1 package in 0.693s
found 0 vulnerabilities
temp $ cd node_modules/exponential-backoff/
exponential-backoff $ ls
LICENSE README.md doc package.json
Add a jitter
option-where this is used to prevent overloading servers with retries from many clients, a jitter is useful
https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
None of the properties of IBackOffOptions are optional, even though the Readme states that they all are:
export interface IBackOffOptions {
delayFirstAttempt: boolean;
jitter: JitterType;
maxDelay: number;
numOfAttempts: number;
retry: (e: any, attemptNumber: number) => boolean | Promise<boolean>;
startingDelay: number;
timeMultiple: number;
}
The documentation does not describe the units of the maxDelay option. I assume it's milliseconds (ms), but it should be documented in the README.
The current codebase has a private typescript property attemptLimitReached
, which happens to work when used by non typescript implementations, but with a more modern TS implementation will make this property private as well.
As a feature being able to detect the limit being reached is fairly essential. Is there any way to expose a getter or method to detect this?
when numOfAttempts should set to any number it will work only 4 times.
Set value as 1 or anything and check
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.