Maybe you are familiar with cron (http://en.wikipedia.org/wiki/Cron). It's a Unix-based task scheduling system that makes running tasks easy. One problem with it is that it's linked to your platform, and it's not trivial to turn it on and off from code.
Meet node-cron (https://github.com/ncb000gt/node-cron). It's basically the same task scheduler but it runs directly from your Node application, so as long as it is up, your jobs should run.
Our strategy is simple: Periodically select all meetings that need mailing, call our mailer with each of these meetings, and then mark it as emailed.
Following this app's convention, let's separate concerns into their own folders, starting with src/tasks/index.js
, as shown in the following code:
var CronJob = require('cron').CronJob; module.exports = function(models, mailer) { var tasks = {}; tasks.followupMail = require('./followupMail')(models,mailer); tasks.init = function() { (new CronJob('00 */15 * * * *',...