1

I have configured jobs with node-cron and yeah I love this node module to schedule job in node.

Here I have requirement of sending push notification to users which are located in different timezone.I want to send notification to them on specific time.

Let's say I am sending notification at 9 PM so in all listed timezone cron job will trigger at 9 PM.

var CronJob = require('cron').CronJob;
var job = new CronJob('00 30 11 * * 1-5', function() {
  /*
   * Runs every weekday (Monday through Friday)
   * at 11:30:00 AM. It does not run on Saturday
   * or Sunday.
   */
  }, function () {
    /* This function is executed when the job stops */
  },
  true, /* Start the job right now */
  timeZone /* Time zone of this job. */
);

I know all this and I am doing same for one timezone as mentioned in there doc.

timeZone - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone.

But Can I specify multiple timezone here in timezone attribute?

If somebody aware of some other node module can achieve this then let me know?

NOTE : I already know I can configured multiple configuration here for each timezone but what if there are dynamic list.

Satyam Koyani
  • 4,236
  • 2
  • 22
  • 48
  • Similar question that went unanswered: http://stackoverflow.com/questions/32580629/run-a-single-cron-for-multiple-time-zones-node-js – Gaurav Gupta Nov 04 '15 at 10:39
  • I went through same problem and could not find any readymade solution for me. So, i somehow managed to develop a workaround, I maintained a unique list (array in json file) of timezones where registered users reside and whenever their is new entry in this list, i scehdule a new job. Another solution i thought (but dropped later) was, scheduling cron job for all possible Timezone and find out users that belongs to that zone and send push notification. – Gaurav Gupta Nov 04 '15 at 10:45
  • Ooops, Yeah I didn't find that, Thanks. I will keep watch on that too. – Satyam Koyani Nov 04 '15 at 10:45

1 Answers1

0

I don't know of a way to send a list of timezones to the CRON job but you could change the logic in the method that runs inside the cron job.

You could do this :

  • run the job every half hour
  • if it's a day you want it to run on
  • select users where (convert current GMT time to user timezone - if the db can do this) > 11:30 AM in their timezone && hasn't sent a notification yet
  • send notifications to the returned users.

You might have already gone this route ... just throwing in my 2c

HTH

sirrocco
  • 7,975
  • 4
  • 59
  • 81