updated transactional messages
This commit is contained in:
parent
4f2d66c30c
commit
2486f7b9d8
7 changed files with 353 additions and 46 deletions
|
@ -18,49 +18,80 @@ function feedLoop() {
|
||||||
let query = 'SELECT `id`, `source_url`, `from`, `address`, `subject`, `list`, `segment` FROM `campaigns` WHERE `type`=2 AND `status`=6 AND (`last_check` IS NULL OR `last_check`< NOW() - INTERVAL 10 MINUTE) LIMIT 1';
|
let query = 'SELECT `id`, `source_url`, `from`, `address`, `subject`, `list`, `segment` FROM `campaigns` WHERE `type`=2 AND `status`=6 AND (`last_check` IS NULL OR `last_check`< NOW() - INTERVAL 10 MINUTE) LIMIT 1';
|
||||||
|
|
||||||
connection.query(query, (err, rows) => {
|
connection.query(query, (err, rows) => {
|
||||||
|
connection.release();
|
||||||
if (err) {
|
if (err) {
|
||||||
connection.release();
|
|
||||||
log.error('Feed', err);
|
log.error('Feed', err);
|
||||||
return setTimeout(feedLoop, 15 * 1000);
|
return setTimeout(feedLoop, 15 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rows || !rows.length) {
|
if (!rows || !rows.length) {
|
||||||
connection.release();
|
|
||||||
return setTimeout(feedLoop, 15 * 1000);
|
return setTimeout(feedLoop, 15 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent = tools.convertKeys(rows[0]);
|
let parent = tools.convertKeys(rows[0]);
|
||||||
|
|
||||||
let query = 'UPDATE `campaigns` SET `last_check`=NOW() WHERE id=? LIMIT 1';
|
updateRssInfo(parent.id, true, false, () => {
|
||||||
connection.query(query, [parent.id], err => {
|
|
||||||
connection.release();
|
|
||||||
if (err) {
|
|
||||||
log.error('Feed', err);
|
|
||||||
return setTimeout(feedLoop, 15 * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.verbose('Feed', 'Checking feed %s (%s)', parent.sourceUrl, parent.id);
|
log.verbose('Feed', 'Checking feed %s (%s)', parent.sourceUrl, parent.id);
|
||||||
feed.fetch(parent.sourceUrl, (err, entries) => {
|
feed.fetch(parent.sourceUrl, (err, entries) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.error('Feed', err);
|
log.error('Feed', err);
|
||||||
return setTimeout(feedLoop, 1 * 1000);
|
return updateRssInfo(parent.id, false, 'Feed error: ' + err.message, () => {
|
||||||
|
setTimeout(feedLoop, 1 * 1000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
checkEntries(parent, entries, (err, result) => {
|
checkEntries(parent, entries, (err, result) => {
|
||||||
|
let message;
|
||||||
if (err) {
|
if (err) {
|
||||||
log.error('Feed', err);
|
log.error('Feed', err);
|
||||||
}
|
message = 'Feed error: ' + err.message;
|
||||||
if (result) {
|
} else if (result) {
|
||||||
log.verbose('Feed', 'Added %s new campaigns for %s', result, parent.id);
|
log.verbose('Feed', 'Added %s new campaigns for %s', result, parent.id);
|
||||||
|
message = 'Found ' + result + ' new campaing messages from feed';
|
||||||
|
} else {
|
||||||
|
message = 'Found nothing new from the feed';
|
||||||
}
|
}
|
||||||
return setTimeout(feedLoop, 1 * 1000);
|
return updateRssInfo(parent.id, false, message, () => {
|
||||||
|
setTimeout(feedLoop, 1 * 1000);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateRssInfo(id, updateCheck, status, callback) {
|
||||||
|
db.getConnection((err, connection) => {
|
||||||
|
if (err) {
|
||||||
|
log.error('Feed', err.stack);
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
let query;
|
||||||
|
let values;
|
||||||
|
if (updateCheck) {
|
||||||
|
if (status) {
|
||||||
|
query = 'UPDATE `campaigns` SET `last_check`=NOW(), `check_status`=? WHERE id=? LIMIT 1';
|
||||||
|
values = [status, id];
|
||||||
|
} else {
|
||||||
|
query = 'UPDATE `campaigns` SET `last_check`=NOW() WHERE id=? LIMIT 1';
|
||||||
|
values = [id];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
query = 'UPDATE `campaigns` SET `check_status`=? WHERE id=? LIMIT 1';
|
||||||
|
values = [status, id];
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.query(query, values, (err, result) => {
|
||||||
|
connection.release();
|
||||||
|
if (err) {
|
||||||
|
log.error('Feed', err);
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
return callback(null, result.affectedRows);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function checkEntries(parent, entries, callback) {
|
function checkEntries(parent, entries, callback) {
|
||||||
let pos = 0;
|
let pos = 0;
|
||||||
let added = 0;
|
let added = 0;
|
||||||
|
|
|
@ -37,10 +37,12 @@ CREATE TABLE `campaigns` (
|
||||||
`template` int(11) unsigned NOT NULL,
|
`template` int(11) unsigned NOT NULL,
|
||||||
`source_url` varchar(255) CHARACTER SET ascii DEFAULT NULL,
|
`source_url` varchar(255) CHARACTER SET ascii DEFAULT NULL,
|
||||||
`last_check` timestamp NULL DEFAULT NULL,
|
`last_check` timestamp NULL DEFAULT NULL,
|
||||||
|
`check_status` varchar(255) DEFAULT NULL,
|
||||||
`from` varchar(255) DEFAULT '',
|
`from` varchar(255) DEFAULT '',
|
||||||
`address` varchar(255) DEFAULT '',
|
`address` varchar(255) DEFAULT '',
|
||||||
`subject` varchar(255) DEFAULT '',
|
`subject` varchar(255) DEFAULT '',
|
||||||
`html` text,
|
`html` text,
|
||||||
|
`html_prepared` text,
|
||||||
`text` text,
|
`text` text,
|
||||||
`status` tinyint(4) unsigned NOT NULL DEFAULT '1',
|
`status` tinyint(4) unsigned NOT NULL DEFAULT '1',
|
||||||
`scheduled` timestamp NULL DEFAULT NULL,
|
`scheduled` timestamp NULL DEFAULT NULL,
|
||||||
|
@ -170,7 +172,7 @@ CREATE TABLE `segments` (
|
||||||
`created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
`created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `list` (`list`),
|
KEY `list` (`list`),
|
||||||
KEY `name` (`name`),
|
KEY `name` (`name`(191)),
|
||||||
CONSTRAINT `segments_ibfk_1` FOREIGN KEY (`list`) REFERENCES `lists` (`id`) ON DELETE CASCADE
|
CONSTRAINT `segments_ibfk_1` FOREIGN KEY (`list`) REFERENCES `lists` (`id`) ON DELETE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
CREATE TABLE `settings` (
|
CREATE TABLE `settings` (
|
||||||
|
|
|
@ -18,6 +18,7 @@ CREATE TABLE `rss` (
|
||||||
ALTER TABLE `campaigns` ADD COLUMN `parent` int(11) unsigned DEFAULT NULL AFTER `type`;
|
ALTER TABLE `campaigns` ADD COLUMN `parent` int(11) unsigned DEFAULT NULL AFTER `type`;
|
||||||
CREATE INDEX parent_index ON `campaigns` (`parent`);
|
CREATE INDEX parent_index ON `campaigns` (`parent`);
|
||||||
ALTER TABLE `campaigns` ADD COLUMN `last_check` timestamp NULL DEFAULT NULL AFTER `source_url`;
|
ALTER TABLE `campaigns` ADD COLUMN `last_check` timestamp NULL DEFAULT NULL AFTER `source_url`;
|
||||||
|
ALTER TABLE `campaigns` ADD COLUMN `check_status` varchar(255) NULL DEFAULT NULL AFTER `last_check`;
|
||||||
CREATE INDEX check_index ON `campaigns` (`last_check`);
|
CREATE INDEX check_index ON `campaigns` (`last_check`);
|
||||||
ALTER TABLE `campaigns` ADD COLUMN `html_prepared` text AFTER `html`;
|
ALTER TABLE `campaigns` ADD COLUMN `html_prepared` text AFTER `html`;
|
||||||
|
|
||||||
|
|
|
@ -98,22 +98,19 @@ body {
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<h1>{{title}}</h1>
|
||||||
|
<p class="lead">Please Confirm Subscription</p>
|
||||||
|
|
||||||
<h1>{{title}}</h1>
|
<p><a href="{{confirmUrl}}" class="btn btn-primary btn-lg">Yes, subscribe me to this list</a></p>
|
||||||
<p class="lead">Please Confirm Subscription</p>
|
|
||||||
|
|
||||||
<p><a href="{{confirmUrl}}" class="btn btn-primary btn-lg">Yes, subscribe me to this list</a></p>
|
<p>If you received this email by mistake, simply delete it. You won't be subscribed if you don't click the confirmation link above.</p>
|
||||||
|
|
||||||
<p>If you received this email by mistake, simply delete it. You won't be subscribed if you don't click the confirmation link above.</p>
|
<p>For questions about this list, please contact:
|
||||||
|
<br/>{{contactAddress}}</p>
|
||||||
|
|
||||||
<p>For questions about this list, please contact:
|
|
||||||
<br/>{{contactAddress}}</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue