email job update only in server

This commit is contained in:
vjrj 2018-04-06 13:01:12 +02:00
parent e6a84852fa
commit 253a658bcc

View file

@ -23,7 +23,9 @@ export const hr = `<table cellspacing="0" cellpadding="0" border="0" width="100%
let MailQueue;
if (Meteor.settings.private.isMailServer && isMaster()) {
const isMailServerMaster = Meteor.settings.private.isMailServer && isMaster();
if (isMailServerMaster) {
console.log('I\'m the mail server');
MailQueue = new MailTime({
db,
@ -84,30 +86,31 @@ if (Meteor.settings.private.testMailer) {
sendMail(emailOpts, true);
}
if (isMailServerMaster) {
// Set interval to greater than 256
// https://github.com/VeliovGroup/Mail-Time/issues/5
const MailJobs = new Mongo.Collection('__JobTasks__mailTimeQueue', { idGeneration: 'MONGO' });
// Set interval to greater than 256
// https://github.com/VeliovGroup/Mail-Time/issues/5
const MailJobs = new Mongo.Collection('__JobTasks__mailTimeQueue', { idGeneration: 'MONGO' });
const updateJob = (mailJob, updated) => {
const updateJob = (mailJob, updated) => {
const delay = 60000;
if (Meteor.isDevelopment) console.log(`${updated ? 'Update old' : 'Update just added'} mailjob with ${delay} delay`);
if (mailJob.delay !== delay) {
MailJobs.update(mailJob._id, { $set: { delay } });
}
};
};
const mailJob = MailJobs.findOne();
const mailJob = MailJobs.findOne();
if (mailJob) {
if (mailJob) {
updateJob(mailJob);
}
}
MailJobs.find().observe({
MailJobs.find().observe({
added: function notifAdded(item) {
updateJob(item, false);
},
changed: function notifChanged(item) {
updateJob(item, true);
}
});
});
}