最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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
});
发布评论

评论列表(0)

  1. 暂无评论