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.

Bull is not removing idle keys from Redis for completed/failed jobs

See original GitHub issue

I read this issue https://github.com/taskforcesh/bullmq/issues/225 and added the options the remove jobs on complete and fail by default. Ended up with something like this:

const defaultJobOptions = { removeOnComplete: true, removeOnFail: true };
const channelQueue = new Queue("Channel", {
  connection: redis,
  defaultJobOptions: defaultJobOptions,
});

Then every time I need to add a new job, I’m just using that queue with the job options if necessary, i.e.

await channelQueue.add("syncAll", {}, { repeat: { cron: "15 * * * *" } });

If I look at the keys stored in Redis, I can find old/idle keys for completed jobs that are not being deleted

{
    name: 'syncAll',
    data: '{}',
    opts: '{"attempts":0,"delay":3599963,"repeat":{"cron":"15 * * * *","count":2438},"jobId":"repeat:syncAll:cb9618d676fe6cb7fc182b28022e33bd:1619752500000","timestamp":1619748900037,"prevMillis":1619752500000}',
    timestamp: '1619748900037',
    delay: '0',
    priority: '0',
    processedOn: '1619752500200',
    returnvalue: 'null',
    finishedOn: '1619752500225'
  }

I have a QueueScheduler too but doesn’t seem to have an option to add removeOn* behaviour

const channelScheduler = new QueueScheduler("Channel", { connection: redis });
await channelScheduler.waitUntilReady();

Is there anything missing on my config or it’s not working as expected?

I’m using bullmq “1.14.0”

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
roggervalfcommented, Jun 19, 2021

@jcalvento I tried to reproduce it using some tests without success 😦, maybe you can change something in these tests to reproduce the issue:

it.only('should remove job after completed if removeOnComplete', async () => {
      const queueScheduler = new QueueScheduler(queueName);
      await queueScheduler.waitUntilReady();
  
      const worker = new Worker(queueName, async (job, token) => {
        expect(token).to.be.string;
        expect(job.data.foo).to.be.equal('bar');
      });
      await worker.waitUntilReady();

      const job = await queue.add(
        'test',
        { foo: 'bar' },
       { repeat: { cron: '*/2 * * * * *' },
        removeOnComplete: true },
      );
      expect(job.id).to.be.ok;
      expect(job.data.foo).to.be.eql('bar');

      return new Promise((resolve, reject) => {
        worker.on('completed', async (job: Job) => {
          try {
            const gotJob = await queue.getJob(job.id);
            expect(gotJob).to.be.equal(undefined);
            const counts = await queue.getJobCounts('completed');
            expect(counts.completed).to.be.equal(0);
            await worker.close();
            resolve();
          } catch (err) {
            reject(err);
          }
        });
      });
    });

    it.only('should remove a job after completed if the default job options specify removeOnComplete', async () => {
      const newQueue = new Queue(queueName+2, {
        defaultJobOptions: {
          removeOnComplete: true,
        },
      });
      const queueScheduler = new QueueScheduler(queueName+2);
      await queueScheduler.waitUntilReady();

      const worker = new Worker(queueName+2, async job => {
        expect(job.data.foo).to.be.equal('bar');
      });
      await worker.waitUntilReady();

      const job = await newQueue.add('test', { foo: 'bar' }, { repeat: { cron: '*/2 * * * * *' } });
      expect(job.id).to.be.ok;
      expect(job.data.foo).to.be.eql('bar');

      return new Promise((resolve, reject) => {
        worker.on('completed', async job => {
          try {
            const gotJob = await newQueue.getJob(job.id);
            expect(gotJob).to.be.equal(undefined);
            const counts = await newQueue.getJobCounts('completed');
            expect(counts.completed).to.be.equal(0);
            await worker.close();
            await newQueue.close();
            resolve();
          } catch (err) {
            reject(err);
          }
        });
      });
    });
1reaction
rbalainecommented, Jun 4, 2021

Hello,

We have the same issue (using bullmq 1.30.2). We set { removeOnComplete: true } in all our queues defaultJobOptions. It’s working fine for all jobs except those with repeat option. We define one QueueScheduler instance per queue with a dedicated Redis connection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bull is not removing idle keys from Redis for completed/failed ...
I read this issue https://github.com/taskforcesh/bullmq/issues/225 and added the options the remove jobs on complete and fail by default.
Read more >
OptimalBits/bull - Gitter
i am facing a problem using bull with redis. on multiple job creation certain jobs are moving to completion without being processed. Can...
Read more >
Welcome to Bull's Guide - GitHub Pages
When a job stalls, depending on the job settings the job can be retried by another idle worker or it can just move...
Read more >
Ability to provide insights from Redis Bull Queue data
I'm fairly new to Redis and Bull, and I'm trying to figure out how to query this data (using Redis in Node. js)...
Read more >
Troubleshooting - Amazon ElastiCache for Redis
Network ACLs are assigned to subnets, not specific resources. ... use of commands that act upon multiple values, keys, or data types must...
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