bull icon indicating copy to clipboard operation
bull copied to clipboard

[BUG] moveToCompleted is throwing errors

Open akirilyuk opened this issue 5 years ago • 5 comments

Description

When trying to move all jobs to completed, I get an exception. However I do not understand why this is happening, maybe I am using something wrrong.

Minimal, Working Test code to reproduce the issue.

const Queue = require('bull');

const queue = new Queue('testqueue', 'redis://127.0.0.1:6379');

const testQueue = async () => {
  queue.add({ test: 'data' });
  const jobs = await queue.getJobs();
  jobs.forEach(async job => {
    await job.moveToCompleted('completed', true, true);
  });
};

testQueue();

yields:

(node:4296) UnhandledPromiseRejectionWarning: TypeError: job.queue.client.moveToFinished is not a function at Object.moveToFinished (/Users//node_modules/bull/lib/scripts.js:167:29) at Object.moveToCompleted (/Users/node_modules/bull/lib/scripts.js:194:20) at Job.moveToCompleted (/Users//node_modules/bull/lib/job.js:194:18) at jobs.forEach (/Users//src/queueTest.js:9:15) at Array.forEach () at testQueue (/Users/**/src/queueTest.js:8:8) at process._tickCallback (internal/process/next_tick.js:68:7)

Bull version

3.10.0

akirilyuk avatar Jul 12 '19 08:07 akirilyuk

Please await the call queue.add({ test: 'data' });.

stansv avatar Jul 12 '19 10:07 stansv

Hi,

this wont help. Basically I want to have a setup for debugging, where I always add a job to a clean queue from start, without the need to manually remove them via a DB manager.

const Queue = require('bull');

const queue = new Queue('testqueue', 'redis://127.0.0.1:6379');

const testQueue = async () => {
  const jobs = await queue.getJobs();
  jobs.forEach(async job => {
    // sometimes returned job is null, so I need a check
    if(job){
      await job.moveToCompleted('completed', true, true);
    }
  });
  await queue.empty();
  // this should be the only job now in the new queue
  await queue.add({ test: 'data' });
};

testQueue();

The above code works, if the redis DB is completely empty. As soon as I restart the code on a non empty redis db, it yields the following error:

(node:4296) UnhandledPromiseRejectionWarning: TypeError: job.queue.client.moveToFinished is not a function at Object.moveToFinished (/Users//node_modules/bull/lib/scripts.js:167:29) at Object.moveToCompleted (/Users/node_modules/bull/lib/scripts.js:194:20) at Job.moveToCompleted (/Users//node_modules/bull/lib/job.js:194:18) at jobs.forEach (/Users//src/queueTest.js:9:15) at Array.forEach () at testQueue (/Users/**/src/queueTest.js:8:8) at process._tickCallback (internal/process/next_tick.js:68:7)

Edit:

At least it looks like all existing jobs are removed:

Screen Shot 2019-07-12 at 13 16 53

akirilyuk avatar Jul 12 '19 11:07 akirilyuk

My worker code looks a bit different and there somehow no jobs are removed at all: what could be the reason for this?

       const queue = new BullQueue('testqueue', 'redis://127.0.0.1:6379', {
          settings: {
            backoffStrategies: {
              botConnector
            }
          }
        });
        const jobs = await this.queue.getJobs();
        jobs.forEach(async job => {
          try {
            await job.moveToCompleted('completed', true, true);
          } catch (err) {
            // ignore err
          }
        });
        await this.queue.empty();
        await this.queue.add({test: 'job'}, {
          attempts: 99999,
          backoff: {
            type: 'botConnector'
          }
        });
        this.queue.process(10, async(data => {
          //do processing here
          return;
        }));

Screen Shot 2019-07-12 at 13 23 23

akirilyuk avatar Jul 12 '19 11:07 akirilyuk

Got it, add await queue.isReady() before your forEach loop.

Looks like there is indeed a bug, moveToCompleted() should wait until queue become ready.

PS I've also answered here https://github.com/OptimalBits/bull/issues/1323 how to completely remove all queue-related keys from Redis which can be helpful for unit tests.

stansv avatar Jul 12 '19 13:07 stansv

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 12 '21 20:07 stale[bot]