Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node Bull Queue Error: Missing process handler for job type JOB_NAME

I am creating node bull queue and passing a dynamic name as an option to the Queue.add function

myQueue.add(`myJob-${val}`, {
    attempts: 3,
    removeOnFail: true
});

I am defining the process name as below for the above job

myQueue.process(`myJob-${val}`, async (job, callback) => {
    try {
        console.log('Processing job', job.id, job.data);
        callback();

    } catch (err) {
        console.log(err);
    }
});

However, I am getting below error

Job ID 1 failed Error: Missing process handler for job type myJob-123

How to correctly define the processor with a dynamic name value?

like image 797
meallhour Avatar asked Jun 13 '26 23:06

meallhour


1 Answers

The mistake you are making is passing extra fields in the add method.
Remove the name value from add method everything will work
only two parameters you have to pass while adding a job::--> data and options

myQueue.add({dummydatakey:"dummydataval"}, {attempts: 3,removeOnFail: true});

A sample job handler file for your Ref:

const Queue = require('bull'); 

module.exports = {

jobStatusCheckScheduler: async function () {
    console.log('hi')
    // 1. Initiating the Queue
    const statusCheckQueue = new Queue("JobStatusCheck", {
        redis: {
            host: "127.0.0.1",
            port: 6379,
        },
    });

    const options = {            
        attempts: 3,
        removeOnFail: true,
        repeat: {
            every: 10000,
            limit: 5,
        },
    };

    // 2. Adding function in the job
    statusCheckQueue.process(async (job, callback) => {
        try {
            console.log('Processing job', job.id, job.data);
            callback();

        } catch (err) {
            console.log(err);
        }
    }).then(() => {
        console.log('suresh')
    }).catch((err) => {
        console.log(err)
    })

    // 3. Adding a Job to the Queue
    await statusCheckQueue.add( {user: '1'}, options).then((job) => {
        console.log('suresh first', job.id)
    }).catch((err) => {
        console.log(err)
    })

    // 4. Listener
    statusCheckQueue.on("error", (err) => {
        console.log(`Job error ${err}`);
    });

    statusCheckQueue.on("progress", function (job, progress) {
        // A job's progress was updated!
    });

    statusCheckQueue.on("completed", (job, result) => {
        console.log("Job completed", job.data);
    });

    statusCheckQueue.on("failed", function (job, err) {
        // A job failed with reason `err`!
        console.log(`Job not completed failed ${err}`);
    });
}

};

like image 159
Suresh Pattu Avatar answered Jun 15 '26 14:06

Suresh Pattu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!