1

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);
  }
});
key joshua
  • 11
  • 2
  • Hi key joshua and welcome to SO. Please share your code, what you have tried? What doesn't work? How is your heroku setup? Its impossible to solve the problem "my code does not work on heroku" – Bergur Dec 09 '21 at 17:58
  • Hello @Bergur, Hopefully, you are doing great and safe. Meantime, I just added codes sample now you can have a look at it. – key joshua Dec 10 '21 at 12:15

0 Answers0