1

I need to remove specific individual job from queue. actual case is I've added a job into queue and then in some API call I need to remove that individual job from the queue. so, It won't be repeat in future.

add:

const job = await this.locationQueue.add('alert', { handle, author, data }, { repeat: { every: 60000 } });

remove:

await this.locationQueue.removeRepeatable('alert', { jobId: request.jobKey, every: 60000 });

Where request.jobKey is job.id from add.

Harsh Makwana
  • 237
  • 3
  • 13

3 Answers3

1

Firstly you need to create your job with a specified jobId:

await queue.add('job-name', user.id, {
  repeat: { every: 1000 },
  jobId: 'job-id',
});

Then you can delete it like this by combining job name, id and delay:

await queue.removeRepeatableByKey(
  'job-name:job-id::1000',
);

Note that there are 2 colons specified after delay.

Leviathan
  • 53
  • 1
  • 7
0

You need to specify the same jobId when you adding it to the queue, as far as I know.

const job = await this.locationQueue.add('alert', { handle, author, data, jobId: 'some job unique job id'}, { repeat: { every: 60000 } });
Ayzrian
  • 2,279
  • 1
  • 7
  • 14
  • but jobId is auto generated by the bullmq. so, I'm trying to save that in a db and when I need to remove that job. I'm getting that from db and pass it into remove job. but It's not working as expected. – Harsh Makwana May 06 '21 at 14:42
  • You can consult the documentation https://docs.bullmq.io/guide/jobs/repeatable I think it may have an answer for you. – Ayzrian May 06 '21 at 14:46
0

When adding a new job in the queue, you need to specify a jobId for your situation, as mentioned by @Ayzrian's answer.

But that jobId should be provided by you, and not the one which BullMQ generates for itself.

The id of a job that BullMQ generates is for later use, when job has already been queued.

The jobId that you'll provide when queuing the repeatable job should be the same which you'll use while removing the same repeatable job (along with other parameters, as mentioned in BullMQ docs).

ranjanistic
  • 111
  • 6