should only grab once an hour now

This commit is contained in:
Martin Donnelly 2016-09-09 14:51:52 +01:00
parent 08d0545da1
commit 4ff2d0c759

View File

@ -27,11 +27,46 @@ var todayCache = {
};
var file = __dirname + '/' + 'newdata.json';
var htmlfile = __dirname + '/' + 'today.html';
function runable() {
try{
var now = new Date().getTime();
if (now - todayCache.last < 360000) {
return false;
} else {
todayCache.last = now;
return true;
}
}
catch(e)
{
todayCache.last = new Date().getTime();
return true;
}
}
function loadData() {
console.log('Loading old data');
try {
todayCache = jsonfile.readFileSync(file);
}
catch(e)
{
console.error('Could not load previous data');
}
}
function saveData() {
todayCache.last = new Date().getTime();
logger.info('Saving...');
jsonfile.writeFileSync(file, todayCache);
}
function saveToDB(data) {
saveData();
logger.debug('Inserting into couch...');
// Logger.info(util.inspect(obj));
dbCouch.insert(data, function(err, body, header) {
@ -241,7 +276,12 @@ module.exports = {
};
setTimeout(function() {
module.exports.preLoadToday();
loadData();
if (runable()) {
module.exports.preLoadToday();
}
//module.exports.preLoadToday();
}, 5000);
setTimeout(function() {
@ -251,7 +291,10 @@ setTimeout(function() {
}, 45000);
cron.schedule('45 6 * * *', function() {
module.exports.preLoadToday();
if (runable()) {
module.exports.preLoadToday();
}
return -1;
});
cron.schedule('0 */1 * * *', function() {