Created
May 21, 2018 22:27
-
-
Save adover/1ebf56b1302a2394d15669082d4c69e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cron = require('node-cron'); | |
const each = require('lodash/each'); | |
/** | |
* Put all schedules in here so they get run through the validator | |
* You may wonder why these have specific names... ideally | |
* we don't ever want jobs to run together as thats | |
* risking putting load on the app unnecessarily | |
*/ | |
const schedules = { | |
test: '* * * * * *', | |
leave: '0 10,18 * * 1-5', | |
timeEntered: '0 13 * * 1', | |
debtor: '0 9 5 * *', | |
creditor: '0 8 5 * *', | |
}; | |
/** | |
* IIFE to validate the jobs. If one of them is invalid it will | |
* break and throw an error. | |
*/ | |
((sched, c) => { | |
each(sched, (s) => { | |
if (!c.validate(s)) { | |
const errorMessage = `Schedules contains invalid cron expression: ${s}`; | |
throw new Error(errorMessage); | |
} | |
}); | |
return true; | |
})(schedules, cron); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment