question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use moveToFailed and moveToCompleted

See original GitHub issue

Issuehunt badges

These two functions are different from v3 and I just don’t know what to set for the token.

job.moveToFailed(new Error('failed message'), ???);


IssueHunt Summary

manast manast has been rewarded.

Backers (Total: $40.00)

Submitted pull Requests


Tips

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:60 (25 by maintainers)

github_iconTop GitHub Comments

2reactions
rileyai-devcommented, Feb 24, 2021

@manast Of course, sorry about that…

const { Queue, QueueScheduler, Worker } = require('bullmq');

const connection = {connection: {port: '6379', host: 'localhost'}};
const queue = new Queue('myqueue', connection).on("error", (err) =>{console.log(err);});
new QueueScheduler('myqueue', Object.assign({stalledInterval: 1000, maxStalledCount:Number.MAX_SAFE_INTEGER}, connection)).on("error", (err) =>{console.log(err);});

(async () =>{
    await queue.add('test1', {}, {
        attempts: Number.MAX_SAFE_INTEGER
    }).catch(err => {
        console.log(err);
    });
    await queue.add('test2', {}, {
        attempts: Number.MAX_SAFE_INTEGER
    }).catch(err => {
        console.log(err);
    });
    await queue.add('test3', {}, {
        attempts: Number.MAX_SAFE_INTEGER
    }).catch(err => {
        console.log(err);
    });

    async function getJob(complete){
        const worker = new Worker('myqueue', null, Object.assign({lockDuration: 2000}, connection));
        const next = await worker.getNextJob('test@gmail.com');

        if(complete){
            const job = await queue.getJob(next.id);
            if(job){
                console.log('complete: ' + next.id);
                await job.moveToCompleted('completed by: ' + 'test@gmail.com' + ' at: ' + Date.now(), 'test@gmail.com');
            }
        }
    }


    getJob(false);
    setTimeout(getJob, 1000, false);
    setTimeout(getJob, 2000, true);
})()
0reactions
rtroncosocommented, Dec 2, 2021

Thanks for the reply @manast ! That’s definitely the way I’d go for it if I was doing this from scratch, however, we are currently migrating from a previous scheduler system which used HTTP calls to our main core-api service (which also depend on different modules and internal controllers that are already set-up and working).

I tried fiddling around with manually processing jobs and sending the token through the HTTP request itself. I was able to correctly manage the status of the job but, as I expected, there is no way to signal the queueEvents interface that the process is completed from an external service.

For now we are going to keep these external jobs out of the migration, but it would be great if there was a way to manage these kind of implementations (given the amount of people with similar use cases as well) and I’d be willing to help in anything needed for this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use moveToFailed and moveToCompleted - Issuehunt
One will have to manually process the queue to use moveToFailed() ? My approach was to use it like this (simplified) in process...
Read more >
Manually processing jobs - BullMQ
When a Worker is instantiated, the most common usage is to specify a process ... moveToCompleted/moveToFailed" is not used, signalling that the next...
Read more >
moveToCompleted - Bohemia Interactive Community Wiki
Syntax: moveToCompleted person; Parameters: person: Object ... _isCompleted = moveToCompleted _unit; ... See also: moveTo moveToFailed ...
Read more >
Use Bull to Manage Job Queues in a ... - Better Programming
These allow you to manage jobs using a key-value store such as Redis. ... moveToFailed() , and job.moveToCompleted() are all we need.
Read more >
Asynchronous task processing in Node.js with Bull
Before we begin using Bull, we need to have Redis installed. ... a log row to this job-specific job, moveToCompleted , moveToFailed ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found