Skip to content

Instantly share code, notes, and snippets.

@mhmda-83
Created March 20, 2022 15:03
Show Gist options
  • Save mhmda-83/ff5e5245bbed2801da0c02c6e1d671d8 to your computer and use it in GitHub Desktop.
Save mhmda-83/ff5e5245bbed2801da0c02c6e1d671d8 to your computer and use it in GitHub Desktop.
const Queue = require('bull');
const pdfQueue = new Queue('pdf', 'redis://localhost:6379');
const delay = (milliseconds) =>
new Promise((resolve) => setTimeout(resolve, milliseconds));
const CONCURRENCY = 2;
pdfQueue.process(CONCURRENCY, async function (job) {
console.log(`creating pdf ${job.data.fileName}... `);
await delay(2000);
console.log(`pdf ${job.data.fileName} created`);
});
pdfQueue.add({ fileName: 'example1.pdf' });
pdfQueue.add({ fileName: 'example2.pdf' });
pdfQueue.add({ fileName: 'example3.pdf' });
pdfQueue.add({ fileName: 'example4.pdf' });
// output 👇
/*
creating pdf example1.pdf...
creating pdf example2.pdf...
pdf example1.pdf created
pdf example2.pdf created
creating pdf example3.pdf...
creating pdf example4.pdf...
pdf example3.pdf created
pdf example4.pdf created
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment