Using Agenda, is it possible to set jobs to retry after several times after failure?
If it's a repeating job, you can change the nextRunAt
value when it fails and it will run again:
agenda.on("fail", async (error, job) => {
const nextRunAt = new Date();
job.attrs.nextRunAt = nextRunAt;
await job.save();
});
if it's a scheduled job (meaning it doesn't repeat, the above code won't work. You have to create a new job.
agenda.on("fail", async (error, job) => {
if(job.attrs.repeatInterval) {
// create a new job and pass it job.attrs.data
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With