I'm using node-cron for scheduling in my express backend, here is the example. I set my scheduling configuration in index.js, and I've develop the function that will execute by cron in training.js
index.js:
const training = require('./training');
const DAILY = 'DAILY';
const HOURLY = 'HOURLY';
function getCronSchedule(when){
switch (when) {
case DAILY : return "55 22 * * *";
case HOURLY : return "10 * * * *";
}
}
function initJob()
{
training.initJob(getCronSchedule(HOURLY));
training.initJob(getCronSchedule(DAILY));
}
module.exports={
initJob
}
training.js:
function initJob(when)
{
console.log('This is daily scheduling');
console.log('This is hourly scheduling');
}
module.exports={
initJob
}
Currently, the:
This is daily scheduling
This is hourly scheduling
will be printed two times every day, because it printed on daily and hourly scheduling.
What I need is each of them printed once for each day.
This is daily scheduling printed on daily cron and,
This is hourly scheduling printed on hourly cron.
How do I can make it? I dont know how to make the condition, because what I got from param just the cron schedule.