I am trying to send a scheduled notification with the node-cron library and it is working fine in my local system but after deploying the codes to the Heroku server it is not working.
const triggerPushNotification = (notifiction, startMinutes, startHour) => {
console.log('Checked Trigger Push Notification Function ...');
cron.schedule(`${startMinutes} ${startHour} * * *`, async () => {
console.log('Checked Inner Cron ...');
await notificationHelper.pushNotification(notifiction.receiversTokens, notifiction.notificationTitle, notifiction.notificationBody, notifiction.notificationURL, notifiction.notificationImage);
});
};
cron.schedule('*/55 * * * * *', async () => {
console.log('Checked Outer Cron ...');
const notifiction = await notificationHelper.viewScheduledNotification();
const formattedStartDate = `${notifiction.startDate}`;
const formattedEndtDate = `${notifiction.endDate}`;
const fullTodayDate = new Date();
const fullEndDate = new Date(formattedEndtDate);
const fullStartDate = new Date(formattedStartDate);
const startHour = notifiction.time.split(':')[0];
const startMinutes = notifiction.time.split(':')[1];
if (fullStartDate <= fullTodayDate && fullTodayDate <= fullEndDate) {
console.log('Checked Middle Cron ...');
console.log(startHour, ':', startMinutes);
triggerPushNotification(notifiction, startMinutes, startHour);
}
});