Fixed throttling and pausing #243
This commit is contained in:
parent
a7b2c33b30
commit
cff908887f
3 changed files with 117 additions and 83 deletions
|
@ -182,10 +182,10 @@ function createMailer(callback) {
|
|||
module.exports.transport.checkThrottling = null;
|
||||
}
|
||||
|
||||
let throttling = Number(configItems.smtpThrottling) || 0;
|
||||
if (throttling) {
|
||||
let sendingRate = Number(configItems.smtpThrottling) || 0;
|
||||
if (sendingRate) {
|
||||
// convert to messages/second
|
||||
throttling = 1 / (throttling / (3600 * 1000));
|
||||
sendingRate = sendingRate / 3600;
|
||||
}
|
||||
|
||||
let transportOptions;
|
||||
|
@ -236,7 +236,7 @@ function createMailer(callback) {
|
|||
error: logfunc.bind(null, 'error')
|
||||
},
|
||||
maxConnections: Number(configItems.smtpMaxConnections),
|
||||
sendingRate: throttling,
|
||||
sendingRate,
|
||||
tls: {
|
||||
rejectUnauthorized: !configItems.smtpSelfSigned
|
||||
}
|
||||
|
@ -257,19 +257,30 @@ function createMailer(callback) {
|
|||
oldListeners.forEach(listener => module.exports.transport.on('idle', listener));
|
||||
}
|
||||
|
||||
let lastCheck = Date.now();
|
||||
|
||||
if (configItems.mailTransport === 'smtp' || !configItems.mailTransport) {
|
||||
|
||||
let throttling = Number(configItems.smtpThrottling) || 0;
|
||||
if (throttling) {
|
||||
throttling = 1 / (throttling / (3600 * 1000));
|
||||
}
|
||||
|
||||
let lastCheck = Date.now();
|
||||
|
||||
module.exports.transport.checkThrottling = function (next) {
|
||||
if (!throttling) {
|
||||
return next();
|
||||
}
|
||||
let nextCheck = Date.now();
|
||||
let checkDiff = (nextCheck - lastCheck);
|
||||
lastCheck = nextCheck;
|
||||
if (checkDiff < throttling) {
|
||||
log.verbose('Mail', 'Throttling next message in %s sec.', (throttling - checkDiff) / 1000);
|
||||
setTimeout(next, throttling - checkDiff);
|
||||
setTimeout(() => {
|
||||
lastCheck = Date.now();
|
||||
next();
|
||||
}, throttling - checkDiff);
|
||||
} else {
|
||||
lastCheck = nextCheck;
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue