Skip to content

Instantly share code, notes, and snippets.

@evilbuck
Created February 15, 2021 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilbuck/84836a0cb2f63448b18084ad19717fd5 to your computer and use it in GitHub Desktop.
Save evilbuck/84836a0cb2f63448b18084ad19717fd5 to your computer and use it in GitHub Desktop.
rate limiting bull queue example
const Bull = require('bull');
const queue = new Bull('test', {
limiter: {
max: 1,
duration: 1000
}
});
queue.process(async job => {
let { data } = job;
let { fail } = data;
console.log(`x: ${data.x} - ${job.id} - processing`);
if (fail) {
throw new Error('test error');
}
return { tada: job.id };
});
queue.on('failed', (job, error) => {
console.log(`x: ${job.data.x} job ${job.id} failed ${error}`);
});
(async () => {
let myQueue = queue;
await myQueue.clean({ grace: 9000000 });
myQueue.add({ fail: true, x: 200 }, { attempts: 2 });
for (let i = 0; i < 10; i++) {
myQueue.add({ x: i });
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment