This commit is contained in:
Andris Reinman 2016-05-25 23:58:17 +03:00
parent f29a8a1b67
commit 773977dd96
10 changed files with 194 additions and 132 deletions

28
lib/caches.js Normal file
View file

@ -0,0 +1,28 @@
'use strict';
let cache = module.exports.cache = new Map();
module.exports.push = (name, value) => {
if (!cache.has(name)) {
cache.set(name, []);
} else if (!Array.isArray(cache.get(name))) {
cache.set(name, [].concat(cache.get(name) || []));
}
cache.get(name).push(value);
};
module.exports.shift = name => {
if (!cache.has(name)) {
return false;
}
if (!Array.isArray(cache.get(name))) {
let value = cache.get(name);
cache.delete(name);
return value;
}
let value = cache.get(name).shift();
if (!cache.get(name).length) {
cache.delete(name);
}
return value;
};

View file

@ -11,6 +11,7 @@ let isUrl = require('is-url');
let feed = require('../feed');
let log = require('npmlog');
let mailer = require('../mailer');
let caches = require('../caches');
let allowedKeys = ['description', 'from', 'address', 'subject', 'template', 'source_url', 'list', 'segment', 'html', 'text'];
@ -809,6 +810,7 @@ module.exports.pause = (id, callback) => {
connection.release();
return callback(err);
}
caches.cache.delete('sender queue');
return callback(null, true);
});
});
@ -821,7 +823,7 @@ module.exports.reset = (id, callback) => {
return callback(err);
}
if (campaign.status !== 3 && !(campaign.status === 2 && campaign.scheduled > new Date())) {
if (campaign.status !== 3 && campaign.status !== 4 && !(campaign.status === 2 && campaign.scheduled > new Date())) {
return callback(null, false);
}
@ -835,6 +837,8 @@ module.exports.reset = (id, callback) => {
connection.release();
return callback(err);
}
caches.cache.delete('sender queue');
connection.query('DELETE FROM links WHERE campaign=?', [id], err => {
if (err) {
connection.release();