Problem with repeatable jobs
Created by: Exitialis
Hello. I need to repeat job in 10 seconds, after previous completes. How can i do it? I had tried do something like that:
index.ts:
queue.process(10, path.join(__dirname, './processors/processor.js'));
queue.add({name: 'test'}, {
attempts: 3,
removeOnFail: true,
removeOnComplete: true,
repeat: {
cron: "*/10 * * * * *",
endDate: new Date().getTime() + 60 * 10 * 1000
}
});
processor.ts:
import {Job} from "bull";
export default async function(job: Job) {
console.log('Job is running: ', job.data);
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 10000);
})
}
And job is started before previous finishes. The only way I found this is to control manually and add job in the queue after previous is completed, but i need to control end time and max attempts manually.
queue.on("completed", (job: Job) => {
job.data.count += 1;
if (job.data.count < 5) {
queue.add(job.data, {
attempts: 3,
removeOnFail: true,
removeOnComplete: true,
});
}
});