It would be super useful to be able to remove repeatable jobs on a case-by-case basis like this:
queue.process('my-job', 5, async job => {
console.log('processing job');
if (someCriteria) {
await queue.removeRepeatable(job.id)
}
// keep processing
});
Is this feasible?
@manast Can you please explain why removal is so difficult?
I don’t use repeatable jobs at all, because I don’t understand how to delete them. I will be immensely grateful if you implement this functionality.
@kulakowka so why does this method not work for you? https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueremoverepeatable
I did not understand how to delete a task with a custom jobId. But then I studied the tests and found this. I think it would be great if we add examples of using these methods in the documentation.
FWIW I was also just trying to figure this out and removeRepeatableByKey seems to solve my problem. It's unclear how, if at all, I can get removeRepeatable to work with my custom id and repeat: { every: 8.64e+7 (daily) setting
The solution appears to be along these lines:
const jobs = await queue.getRepeatableJobs();
queue.removeRepeatableByKey(jobs[0].key);
When i tried using this method - removeRepeatableByKey I am getting removeRepeatableByKey is not a function error.
queue_1.taskQueue.removeRepeatableByKey is not a function
I am not able to remove my repeatable job by taskQueue.removeRepeatable('task', { cron: '0 47 6 * * 4' }); this too
JSON of the JOB:
{
id: "repeat:09854c8042eced1337a7d8eec9357528:1552526220000",
name: "task",
data: {
eventName: "test",
parameters: [
{
my_JSON
},
{
my_JSON
}
]
},
opts: {
repeat: {
count: 1,
cron: "0 47 6 * * 4",
jobId: "myJobId"
},
jobId: "repeat:09854c8042eced1337a7d8eec9357528:1552526220000",
delay: 603096068,
timestamp: 1551923123932,
prevMillis: 1552526220000,
priority: 1,
attempts: 3,
removeOnComplete: true,
backoff: {
type: "fixed",
delay: 3
},
timeout: 60000
},
progress: 0,
delay: 603096068,
timestamp: 1551923123932,
attemptsMade: 0,
stacktrace: [ ],
returnvalue: null,
finishedOn: null,
processedOn: null
}
I spent a lot of time to make it work. as a result, we had to use cron. ¯_(ツ)_/¯
I just switched from cron to BULL :(
But if removeRepeatableByKey is working for everyone why is it not working for me. pls let me know what am I missing.
@ganeshcse2991 can you provide a complete code snipped so that we can help you?
Why can't we simply remove a repeatable job by ID?
@amitava82 we already have it, removeRepeatableByKey, what do you want to do that you cannot do precisely?
removeRepeatableByKey Does not take the job ID. Assume a case where I my service post a job to bull and gets a jobId back, not the key. When my service wants to delete the job, it does not know the key. So, the solution to me, is that bull should be able to remove a job by given ID or return the key when a job is created.
The problem is that bull cannot either know the repeatable job key from a given job id. What you can do is list all the repeatable jobs and pick the ID that matches the repeatable job that you want to remove.
That won't be ideal when you have 1000s of jobs. Can't you return the key along with other payload when the job is created? I saw in the source there is a piece of code that does the key generation. I suppose I could copy and do it myself.
Any update on this? Is there a way to remove a repeatable by jobId?
Most helpful comment
Why can't we simply remove a repeatable job by ID?