3

I'm completely new to Bull queue and I have a decent understanding of JavaScript. I am trying to get the following example to work:

const Queue = require('bull')

const myFirstQueue = new Queue('my-first-queue');

myFirstQueue.process(async (job, done) => {
  await doSomething(job.data);
  done();
});

const doSomething = data => {
  return new Promise((resolve, reject) => {
    return resolve(data);
  });
};

myFirstQueue.on('completed', (job, result) => {
  log.debug(`Job completed with result ${job}`);
});

(async function ad() {
  const job = await myFirstQueue.add({
  foo: 'bar',
});
})();

The error I'm getting is:

\node_modules\ioredis\built\redis\event_handler.js:177
self.flushQueue(new errors_1.MaxRetriesPerRequestError(maxRetriesPerRequest));
                ^
            

MaxRetriesPerRequestError: Reached the max retries per request limit (which is 20). Refer to "maxRetriesPerRequest" option for details.
    at Socket.<anonymous> (...\node_modules\ioredis\built\redis\event_handler.js:177:37)
    at Object.onceWrapper (node:events:652:26)
    at Socket.emit (node:events:537:28)
    at TCP.<anonymous> (node:net:747:14)

Based off the error I'm getting it seems like the queue cannot process this job at all and I'm not sure why I'm getting this error. I am running the script with the command node fileName.js in the correct directory. I can run other JavaScript files fine that are even more complex than this.

EDIT: Edited code to reflect changes from comments, still have the same error.

Long Nguyen
  • 73
  • 1
  • 6
  • done(); is undefined, read [docs](https://www.npmjs.com/package/bull) its `.process(function (job, done) {` – Lawrence Cherone Jul 29 '22 at 16:57
  • I've changed it to .process(function (job, done) { await doSomething(job.data) ... } and it's still giving me that error. – Long Nguyen Jul 29 '22 at 17:08
  • I've tried that too and still got the error. Even copy pasted the example you linked. I'm at a loss at what else the problem could be... – Long Nguyen Jul 29 '22 at 18:41
  • Can you provide your package.json and environment/setup details necessary to reproduce the problem? Do you have redis set up correctly? – ggorlen Jul 29 '22 at 20:45
  • @ggorlen I'm testing this in a completely new project folder so the only dependency is bull (version 4.8.5 or higher). Used node package manager to install it. I'm under the impression that npm installs redis/required packages for bull to work, so I don't think that is the problem. No .env file used, just a plain js file and the node modules. I am using VS Code to run the script in the terminal. – Long Nguyen Jul 29 '22 at 20:59
  • I'm unable to reproduce the error on Windows with Bull version 3.22.6 or 4.8.5. When I don't use a redis URL, it hangs, which seems to make sense because [Bull requires Redis](https://stackoverflow.com/questions/62901179/bull-without-redis-to-queue-management). When I do use a Redis URL, your code works OK regardless of the ordering. – ggorlen Jul 29 '22 at 22:01
  • @ggorlen I was under the impression you don't need to add redis when you instantiate the queue. According to the official bull README.md (in their Quick Guide section), I see 2 instances where they don't add a redis to the queue, specifically in their example: ```const imageQueue = new Queue('image transcoding');``` . So does that mean this example won't work at all? – Long Nguyen Jul 30 '22 at 17:11
  • 1
    Without passing a URL or `opts` object, theses examples seem to be assuming you have Redis available at the host/port given by the [default Redis options](https://github.com/OptimalBits/bull/blob/b9ea7f4780948d4556548e6bf13e2c3271939d12/lib/queue.js#L127). If you don't have Redis running at the default location, I imagine it won't work. All this is with the caveat that I don't see much guidance in the docs so I'm not 100% sure. I have my system that works for me and I haven't tried setting Redis at the default host/port (I always use Heroku-given URLs), so I might be missing something. – ggorlen Jul 30 '22 at 18:27

1 Answers1

0

Need to add redis URL for connection, because bull uses redis for storing queue data.

const myFirstQueue = new Queue('my-first-queue','redis-url');
Mahesh M
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 08 '23 at 08:27