Search code examples
node.jsagenda

How to run job at certain time and then repeat after that time


i want to send a notification for my users and I need check users states everyday and each user that get this situation send him/her notif. for this purpose i use agenda.js library. when I run this code i want to create a job Once and after that repeat call this job. so for this i write this code:

  const job = await agenda.create(SCHEDULE_MISS_YOU_NOTIF, data)
  job.repeatEvery('40 16 * * *', { timezone: 'Asia/Tehran' })
  await job.save()

but my problem is every time i run this code, immediately i get a notif and after that i get notif on time that scheduled. how can i remove first one notif and why this notif occure?


Solution

  • job.repeatEvery('40 16 * * *', {
      skipImmediate: true,
      timezone: 'Asia/Tehran'
    });