Browse Source

increased cache lifetime to 600s; prevent cache write in groom api

all-modes
pbca26 8 years ago
parent
commit
fba20b5b6c
  1. 37
      routes/cache.js

37
routes/cache.js

@ -152,6 +152,7 @@ cache.groomPost = function(req, res) {
var _filename = req.body.filename, var _filename = req.body.filename,
_payload = req.body.payload; _payload = req.body.payload;
if (!cacheCallInProgress) {
if (_filename) { if (_filename) {
if (!_payload) { if (!_payload) {
var errorObj = { var errorObj = {
@ -185,6 +186,14 @@ cache.groomPost = function(req, res) {
'result': 'no file name provided' 'result': 'no file name provided'
}; };
res.end(JSON.stringify(errorObj));
}
} else {
var errorObj = {
'msg': 'error',
'result': 'another job is in progress'
};
res.end(JSON.stringify(errorObj)); res.end(JSON.stringify(errorObj));
} }
} }
@ -303,9 +312,35 @@ cache.one = function(req, res, next) {
console.log('cache-one call started'); console.log('cache-one call started');
function fixJSON(data) {
console.log(data);
if (data && data.length) {
try {
var parsedJSON = JSON.parse(data);
return parsedJSON;
} catch (e) {
console.log(e);
if (e.toString().indexOf('at position') > -1) {
const errorPos = e.toString().split(' ');
console.log('JSON error ---> ' + data.substring(errorPos[errorPos.length - 1] - 20, errorPos[errorPos.length - 1] + 20) + ' | error sequence: ' + data.substring(errorPos[errorPos.length - 1], errorPos[errorPos.length - 1] + 1));
console.log('attempting to recover JSON data');
return JSON.parse(data.substring(0, errorPos[errorPos.length - 1]));
}
if (e.toString().indexOf('Unexpected end of JSON input')) {
return {};
}
}
} else {
return {};
}
}
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') { if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') {
var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8'); var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8');
outObj = _file ? JSON.parse(_file) : {}; //outObj = _file ? JSON.parse(_file) : {};
outObj = fixJSON(_file);
if (!outObj || !outObj.basilisk) { if (!outObj || !outObj.basilisk) {
console.log('no local basilisk info'); console.log('no local basilisk info');

Loading…
Cancel
Save