Reputation: 994
I am using percolate:synced-cron in my meteor app. I am following the tutorial here http://richsilv.github.io/meteor/scheduling-events-in-the-future-with-meteor/
I am confused in part of
function scheduleMail(details) {
if (details.date < new Date()) {
sendMail(details);
} else {
var thisId = FutureTasks.insert(details);
addTask(thisId, details);
}
return true;
}
and in
FutureTasks.find().forEach(function(mail) {
if (mail.date < new Date()) {
sendMail(mail)
} else {
addTask(mail._id, mail);
}
});
Anyone can explain more about these two part of codes? Also how can I make the task run every day at midnight?
Upvotes: 2
Views: 561
Reputation: 127
The first part send the mail if it's supposed to be send immediately else execute addTask function which create a cron to be executed at a specific date. When the cron is executed the mail is sent and the task and cron then deleted.
the second part is launched at startup to send mail that where not sent when the server is down following the same process
It is my personal opinion that this is rather ineffective since a cron is created then deleted which is not reusable.
If you want to run a cron every day at midnight here how it works:
SyncedCron.add({
name: "NAME",
schedule: function(parser) {
return parser.cron("0 0 * * *");
},
job: function() {
//execute your task
}
});
Upvotes: 2