Change certain values to const

This commit is contained in:
Dennis Jung 2017-02-01 14:05:01 +09:00
parent 461d88f6f2
commit 350e05ab06
4 changed files with 19 additions and 14 deletions

View file

@ -10,9 +10,10 @@ let campaigns = require('../lib/models/campaigns');
function feedLoop() {
db.getConnection((err, connection) => {
const feed_timeout = 15 * 1000;
if (err) {
log.error('Feed', err.stack);
return setTimeout(feedLoop, 15 * 1000);
return setTimeout(feedLoop, feed_timeout);
}
let query = 'SELECT `id`, `source_url`, `from`, `address`, `subject`, `list`, `segment`, `html` FROM `campaigns` WHERE `type`=2 AND `status`=6 AND (`last_check` IS NULL OR `last_check`< NOW() - INTERVAL 10 MINUTE) LIMIT 1';
@ -21,22 +22,23 @@ function feedLoop() {
connection.release();
if (err) {
log.error('Feed', err);
return setTimeout(feedLoop, 15 * 1000);
return setTimeout(feedLoop, feed_timeout);
}
if (!rows || !rows.length) {
return setTimeout(feedLoop, 15 * 1000);
return setTimeout(feedLoop, feed_timeout);
}
let parent = tools.convertKeys(rows[0]);
updateRssInfo(parent.id, true, false, () => {
const rss_timeout = 1 * 1000;
log.verbose('Feed', 'Checking feed %s (%s)', parent.sourceUrl, parent.id);
feed.fetch(parent.sourceUrl, (err, entries) => {
if (err) {
log.error('Feed', err);
return updateRssInfo(parent.id, false, 'Feed error: ' + err.message, () => {
setTimeout(feedLoop, 1 * 1000);
setTimeout(feedLoop, rss_timeout);
});
}
checkEntries(parent, entries, (err, result) => {
@ -51,7 +53,7 @@ function feedLoop() {
message = 'Found nothing new from the feed';
}
return updateRssInfo(parent.id, false, message, () => {
setTimeout(feedLoop, 1 * 1000);
setTimeout(feedLoop, rss_timeout);
});
});
});

View file

@ -221,15 +221,16 @@ function processImport(data, callback) {
let importLoop = () => {
let getNext = () => {
const process_timout = 5 * 1000;
// find an unsent message
findUnprocessed((err, data) => {
if (err) {
log.error('Import', err.stack);
setTimeout(getNext, 5 * 1000);
setTimeout(getNext, process_timout);
return;
}
if (!data) {
setTimeout(getNext, 5 * 1000);
setTimeout(getNext, process_timout);
return;
}
@ -246,7 +247,7 @@ let importLoop = () => {
db.getConnection((err, connection) => {
if (err) {
log.error('Import', err.stack);
return setTimeout(getNext, 5 * 1000);
return setTimeout(getNext, process_timout);
}
let query = 'UPDATE importer SET `status`=?, `error`=?, `finished`=NOW() WHERE `id`=? AND `status`=2 LIMIT 1';

View file

@ -461,6 +461,7 @@ let sendLoop = () => {
}
let getNext = () => {
const mailing_timeout = 5 * 1000;
if (!mailer.transport.isIdle()) {
// only retrieve new messages if there are free slots in the mailer queue
return;
@ -470,11 +471,11 @@ let sendLoop = () => {
findUnsent((err, message) => {
if (err) {
log.error('Mail', err.stack);
setTimeout(getNext, 5 * 1000);
setTimeout(getNext, mailing_timeout);
return;
}
if (!message) {
setTimeout(getNext, 5 * 1000);
setTimeout(getNext, mailing_timeout);
return;
}
@ -483,7 +484,7 @@ let sendLoop = () => {
formatMessage(message, (err, mail) => {
if (err) {
log.error('Mail', err.stack);
setTimeout(getNext, 5 * 1000);
setTimeout(getNext, mailing_timeout);
return;
}

View file

@ -45,20 +45,21 @@ module.exports = callback => {
return callback(err);
}
let checkLoop = () => {
const timezone_timeout = 60 * 60 * 1000;
let curUtcDate = new Date().toISOString().split('T').shift();
if (curUtcDate !== lastCheck) {
updateTimezoneOffsets(err => {
if (err) {
log.error('UTC', err);
}
setTimeout(checkLoop, 60 * 60 * 1000);
setTimeout(checkLoop, timezone_timeout);
});
} else {
setTimeout(checkLoop, 60 * 60 * 1000);
setTimeout(checkLoop, timezone_timeout);
}
lastCheck = curUtcDate;
};
setTimeout(checkLoop, 60 * 60 * 1000);
setTimeout(checkLoop, timezone_timeout);
callback(null, true);
});
};