email job update only in server
This commit is contained in:
parent
e6a84852fa
commit
1570ef7d44
1 changed files with 31 additions and 28 deletions
|
|
@ -23,7 +23,9 @@ export const hr = `<table cellspacing="0" cellpadding="0" border="0" width="100%
|
||||||
|
|
||||||
let MailQueue;
|
let MailQueue;
|
||||||
|
|
||||||
if (Meteor.settings.private.isMailServer && isMaster()) {
|
const isMailServerMaster = Meteor.settings.private.isMailServer && isMaster();
|
||||||
|
|
||||||
|
if (isMailServerMaster) {
|
||||||
console.log('I\'m the mail server');
|
console.log('I\'m the mail server');
|
||||||
MailQueue = new MailTime({
|
MailQueue = new MailTime({
|
||||||
db,
|
db,
|
||||||
|
|
@ -84,30 +86,31 @@ if (Meteor.settings.private.testMailer) {
|
||||||
sendMail(emailOpts, true);
|
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
|
const updateJob = (mailJob, updated) => {
|
||||||
// https://github.com/VeliovGroup/Mail-Time/issues/5
|
|
||||||
const MailJobs = new Mongo.Collection('__JobTasks__mailTimeQueue', { idGeneration: 'MONGO' });
|
|
||||||
|
|
||||||
const updateJob = (mailJob, updated) => {
|
|
||||||
const delay = 60000;
|
const delay = 60000;
|
||||||
if (Meteor.isDevelopment) console.log(`${updated ? 'Update old' : 'Update just added'} mailjob with ${delay} delay`);
|
if (Meteor.isDevelopment) console.log(`${updated ? 'Update old' : 'Update just added'} mailjob with ${delay} delay`);
|
||||||
if (mailJob.delay !== delay) {
|
if (mailJob.delay !== delay) {
|
||||||
MailJobs.update(mailJob._id, { $set: { delay } });
|
MailJobs.update(mailJob._id, { $set: { delay } });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const mailJob = MailJobs.findOne();
|
const mailJob = MailJobs.findOne();
|
||||||
|
|
||||||
if (mailJob) {
|
if (mailJob) {
|
||||||
updateJob(mailJob);
|
updateJob(mailJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
MailJobs.find().observe({
|
MailJobs.find().observe({
|
||||||
added: function notifAdded(item) {
|
added: function notifAdded(item) {
|
||||||
updateJob(item, false);
|
updateJob(item, false);
|
||||||
},
|
},
|
||||||
changed: function notifChanged(item) {
|
changed: function notifChanged(item) {
|
||||||
updateJob(item, true);
|
updateJob(item, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue