6

Hi I am using a node agenda to define a job in my app (https://github.com/rschmukler/agenda). I have two use cases that I do not know how to cover

1) I want the job to run every Tuesday or every Wednesday for example

2) I want the job to run every 5th or 10th of the month.

I know that node agenda uses human interval (https://github.com/rschmukler/human-interval) to interpret how often they want to run the jobs, but I see that it can only interpret units such as days, weeks, months etc. Any idea on how I could cover the two use cases I mentioned above?

For use case 1, I found that I can do something like this (from the agenda documentation):

var weeklyReport = agenda.schedule('Saturday at noon', 'send email report', {to: 'another-guy@example.com'});
weeklyReport.repeatEvery('1 week').save();
agenda.start();
es3735746
  • 841
  • 3
  • 16
  • 40

1 Answers1

4

You can use cron format:

1) weeklyReport.repeatEvery( "0 0 * * 1,4")

Where 1 is Monday and 4 is Thursday

2) weeklyReport.repeatEvery("0 0 1,15 * *")

This will run on the 1st and 15th of the month

aquint
  • 512
  • 3
  • 14
  • The agenda module assumes months are 30 days long, so this won't work exactly as intended. – Blubberguy22 Jun 25 '15 at 19:12
  • Hmm I think thats only the human interval that assumes 30 days – aquint Jun 25 '15 at 19:15
  • This still has the months assumed at 30 days, but it might be for every month calls (every few months, with months being 30 days do something), and not for calls within months. – Blubberguy22 Jun 25 '15 at 19:17
  • The first one should run every Monday and Thursday regardless of the days in a month, and the second runs the 1st and the 15th of every month (or you could change the days to whatever you like) – aquint Jun 25 '15 at 19:27
  • yes; I was under the assumption that the program wouldn't know what month it was. – Blubberguy22 Jun 25 '15 at 19:42