Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] moveToCompleted is throwing errors #1381

Open
akirilyuk opened this issue Jul 12, 2019 · 5 comments
Open

[BUG] moveToCompleted is throwing errors #1381

akirilyuk opened this issue Jul 12, 2019 · 5 comments
Labels

Comments

@akirilyuk
Copy link
Contributor

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

@stansv
Copy link
Contributor

stansv commented Jul 12, 2019

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

@akirilyuk
Copy link
Contributor Author

akirilyuk commented Jul 12, 2019

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
Copy link
Contributor Author

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

@stansv
Copy link
Contributor

stansv commented Jul 12, 2019

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 #1323 how to completely remove all queue-related keys from Redis which can be helpful for unit tests.

@stale
Copy link

stale bot commented Jul 12, 2021

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 stale bot added the wontfix label Jul 12, 2021
@manast manast added bug and removed wontfix labels Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants