删除 Bullmq 中的特定可重复作业使用 jobid

问题描述

我需要从队列中删除特定的单个作业。实际情况是我已将一个作业添加到队列中,然后在某些 API 调用中,我需要从队列中删除该单个作业。所以,以后不会再重复了。

添加

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

删除

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

其中 request.jobKey 是 add 中的 job.id。

解决方法

据我所知,您需要在将其添加到队列时指定相同的 jobId

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