Open dutu opened 4 years ago
I'm just sharing my solution here for this same problem.
const count = 25, time = 1000; // 25 requests per second
const bottleneck = new Bottleneck({ reservoir: count });
bottleneck.on("executing", ({ options }) => {
const weight = options.weight || 1;
if (weight >= 1)
setTimeout(() => bottleneck.incrementReservoir(weight), time);
});
I'm running into the issue described in the documentation:
To overcome the issue, i.e. prevent running more than 5 jobs over a certain interval (say 1 minute), I'm using the code below:
Do you see any issue with this approach or do you have any other suggestion?