0

In the following code sample I am trying to push sampleQueue1, sampleQueue2, sampleQueue3 but I am getting error,

const Queue = require('bull');
const sampleQueue1 = new Queue('sample1', 'redis://127.0.0.1:6379');
const sampleQueue2 = new Queue('sample2', 'redis://127.0.0.1:6379');
const sampleQueue3 = new Queue('sample3', 'redis://127.0.0.1:6379');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

const queueProcess = async(job, done) => {
    console.log(job.data);
        await delay(5 * 1000);
        job.log("Testing Log");
        if(job.data % 2 == 0)
                done(null, "even number");
        else
                done(new Error('error transcoding'));
}
sampleQueue1.process(queueProcess);
sampleQueue2.process(queueProcess);
sampleQueue3.process(queueProcess);
let queues = [sampleQueue1, sampleQueue2, sampleQueue3]
(async() => {
    await sampleQueue.obliterate({ force: true });
    array = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
    array.forEach(val => {
        console.log(val);
        let rand = Math.floor(Math.random() * queues.length);
        queues[rand].add(val);
    });
})();
console.log("Job done");

When I run the above code, I am getting the following error,

/test.js:16
(async() => {
^

TypeError: [sampleQueue] is not a function

Help me to fix this issue.

sel
  • 169
  • 5
  • 13
  • Does this answer your question? [What does the leading semicolon in JavaScript libraries do?](https://stackoverflow.com/questions/1873983/what-does-the-leading-semicolon-in-javascript-libraries-do) – ggorlen Jul 24 '22 at 04:54
  • You missed a semicolon on the `let queues = [sampleQueue1, sampleQueue2, sampleQueue3]` line. The code is trying to call `[]()` and arrays are not functions. – ggorlen Jul 24 '22 at 04:54

0 Answers0