javascript - BullMQ Job Not Removed from Queue After Calling job.remove() - Stack Overflow

I’m prototyping a project using BullMQ and Redis, and so far, everything seems to be working fine. Jobs

I’m prototyping a project using BullMQ and Redis, and so far, everything seems to be working fine. Jobs are being added to the queue successfully. However, when I process the jobs using a worker and call job.remove() after completing the job, the job is not removed from the queue.

The queue remains filled with the job, and I have to manually run the FLUSHDB command in redis-cli to reset the contents of the queue.

Here is the code I’m using for the prototype:

import { Queue, Worker } from 'bullmq';
import { Redis } from 'ioredis';

const redis_connection = new Redis({
    host: 'localhost',
    port: 6379,
    maxRetriesPerRequest: null 
})


const myQueue = new Queue('my-queue',{
    connection:redis_connection,
});

// Add jobs to the queue
for (let i = 0; i < 50; i++) {
    myQueue.add('myJob', { foo: 'bar' , jobNumber: i });
}

const myWorker = new Worker('my-queue', async (job) => {
    // Process the job data
    console.log('Processing job:', job.data);
// even adding job.remove() here doesnt remove the job from the queue
  }, {
    connection: redis_connection,
  });

  myWorker.on('completed', async (job) => {
    console.log(`Job with ID ${job.id} has been completed.`);
    await job.remove(); // Should removes the job from the queue
});

myWorker.on('failed', async (job, err) => {
    console.error(`Job with ID ${job.id} has failed with error: ${err.message}`);
    await job.remove(); // Should remove the job from the queue
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745293998a4621030.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信