Browse Source

Merge pull request #106 from pbca26/master

agama
all-modes
pbca26 8 years ago
committed by GitHub
parent
commit
9eda1a018f
  1. 75
      routes/cache.js
  2. 2
      routes/shepherd.js

75
routes/cache.js

@ -141,8 +141,8 @@ cache.groomDelete = function(req, res, next) {
if (_filename) { if (_filename) {
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) { if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) {
inMemCache = {}; inMemCache = null;
fs.unlink(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', function(err) { fs.unlink(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', function(err) {
if (err) { if (err) {
const errorObj = { const errorObj = {
@ -183,6 +183,8 @@ cache.groomPost = function(req, res) {
_payload = req.body.payload; _payload = req.body.payload;
if (!cacheCallInProgress) { if (!cacheCallInProgress) {
cacheCallInProgress = true;
if (_filename) { if (_filename) {
if (!_payload) { if (!_payload) {
const errorObj = { const errorObj = {
@ -192,31 +194,29 @@ cache.groomPost = function(req, res) {
res.end(JSON.stringify(errorObj)); res.end(JSON.stringify(errorObj));
} else { } else {
if (inMemCache) { inMemCache = JSON.parse(_payload);
inMemCache = JSON.parse(_payload); console.log('appending groom post to in mem cache');
console.log('appending groom post to on disk cache');
console.log('appending groom post to in mem cache'); fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', _payload, function (err) {
} else { if (err) {
console.log('appending groom post to on disk cache'); const errorObj = {
'msg': 'error',
fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', _payload, function (err) { 'result': err
if (err) { };
const errorObj = {
'msg': 'error',
'result': err
};
res.end(JSON.stringify(errorObj)); cacheCallInProgress = false;
} else { res.end(JSON.stringify(errorObj));
const successObj = { } else {
'msg': 'success', const successObj = {
'result': 'done' 'msg': 'success',
}; 'result': 'done'
};
res.end(JSON.stringify(successObj)); cacheCallInProgress = false;
} res.end(JSON.stringify(successObj));
}); }
} });
} }
} else { } else {
const errorObj = { const errorObj = {
@ -289,15 +289,14 @@ cache.one = function(req, res, next) {
if (!cacheCallInProgress) { if (!cacheCallInProgress) {
cache.dumpCacheBeforeExit(); cache.dumpCacheBeforeExit();
fs.readFile(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json', 'utf8', function (err, data) {
if (data) { let _data = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json', 'utf8');
inMemCache = JSON.parse(data); if (_data) {
data = data.replace('waiting', 'failed'); inMemCache = JSON.parse(_data);
/*fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json', data, function(err) { _data = _data.replace('waiting', 'failed');
});*/
cache.dumpCacheBeforeExit(); cache.dumpCacheBeforeExit();
} }
});
// TODO: add check to allow only one cache call/sequence in progress // TODO: add check to allow only one cache call/sequence in progress
cacheCallInProgress = true; cacheCallInProgress = true;
@ -322,16 +321,6 @@ cache.one = function(req, res, next) {
} }
inMemCache = outObj; inMemCache = outObj;
/*fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', JSON.stringify(outObj), function(err) {
if (err) {
return console.log(err);
}
console.log('file ' + cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json is updated');
if (timeStamp) {
console.log('file ' + cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json is timestamped');
}
});*/
}, },
checkTimestamp = function(dateToCheck) { checkTimestamp = function(dateToCheck) {
var currentEpochTime = new Date(Date.now()) / 1000, var currentEpochTime = new Date(Date.now()) / 1000,
@ -394,9 +383,11 @@ cache.one = function(req, res, next) {
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') { if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') {
if (inMemCache) { if (inMemCache) {
console.log('cache one from mem');
outObj = inMemCache; outObj = inMemCache;
} else { } else {
var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8'); var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8');
console.log('cache one from disk');
//outObj = _file ? JSON.parse(_file) : {}; //outObj = _file ? JSON.parse(_file) : {};
outObj = fixJSON(_file); outObj = fixJSON(_file);
} }

2
routes/shepherd.js

@ -185,7 +185,7 @@ shepherd.post('/appconf', function(req, res, next) {
res.end(JSON.stringify(errorObj)); res.end(JSON.stringify(errorObj));
} else { } else {
shepherd.saveLocalAppConf(req.body.payload); shepherd.saveLocalAppConf(JSON.parse(req.body.payload));
const errorObj = { const errorObj = {
'msg': 'success', 'msg': 'success',

Loading…
Cancel
Save