Fix race condition on message

This commit is contained in:
Paul Sori 2018-09-19 23:58:35 -04:00
parent 068f0009df
commit c1cdcb03bf
3 changed files with 14 additions and 36 deletions

View File

@ -53,7 +53,7 @@ function* scanDirectory(directoryToScan) {
yield dbRead.setup(loadJson.dbSettings.dbPath, loadJson.saveInterval, function () {
parseFilesGenerator.next();
});
process.stdout.write(JSON.stringify({msg: `File scan started at ${Date.now()}`}));
// Pull filelist from DB
pullFromDB();
// Loop through current files and compare them to the files pulled from the DB
@ -74,7 +74,7 @@ function* scanDirectory(directoryToScan) {
yield dbRead.savedb(() => {
parseFilesGenerator.next();
});
process.stdout.write(JSON.stringify({msg: `File scan successfully finished at ${Date.now()}`}));
// Exit
process.exit(0);
}

View File

@ -21,28 +21,6 @@ exports.setup = function (mstream, program) {
});
});
// TODO: Is this still necessary???
// mstream.get('/db/download-db', function(req, res){
// // Download File
// res.download(req.user.privateDBOptions.importDB);
// });
// // Get hash of database
// mstream.get( '/db/hash', function(req, res){
// var hash = crypto.createHash('sha256');
// hash.setEncoding('hex');
//
// var fileStream = fs.createReadStream(req.user.privateDBOptions.importDB);
// fileStream.on('end', function () {
// hash.end();
// res.json( {hash:String(hash.read())} );
// });
//
// fileStream.pipe(hash, { end: false });
// });
// Scan library
mstream.get('/db/recursive-scan', function (req, res) {
var scan = runScan();
@ -64,19 +42,19 @@ exports.setup = function (mstream, program) {
}
const forkedScan = child.fork(fe.join(__dirname, 'database-default-manager.js'), [JSON.stringify(jsonLoad)], { silent: true });
console.log(`File scan started at ${Date.now()}`);
forkedScan.stdout.on('data', (data) => {
try {
var json = JSON.parse(data, 'utf8');
console.log(`stdout: ${json.msg}`);
var parsedMsg = JSON.parse(data, 'utf8');
console.log(`stdout: ${parsedMsg.msg}`);
// TODO: Ideally, if there are no changes to the DB we should not be reloading it. Ideally...
if(parsedMsg.loadDB === true) {
parseFlag = true;
mstreamReadPublicDB.loadDB();
}
} catch (error) {
console.log(`stdout: ${data}`);
}
// TODO: Ideally, if there are no changes to the DB we should not be reloading it. Ideally...
if(json.loadDB === true) {
parseFlag = true;
mstreamReadPublicDB.loadDB();
return;
}
});
forkedScan.stderr.on('data', (data) => {
@ -87,8 +65,8 @@ exports.setup = function (mstream, program) {
if(parseFlag === false) {
mstreamReadPublicDB.loadDB();
}
console.log(`file scan completed with code ${code} at ${Date.now()}`);
callback();
console.log(`file scan completed with code ${code}`);
});
}

View File

@ -32,7 +32,7 @@ function saveDB(cb) {
if (err) {
console.error("error : " + err);
} else {
process.stdout.write(JSON.stringify({msg: 'database saved', loadDB: true}));
console.log(JSON.stringify({msg: 'database saved', loadDB: true}));
}
if(cb) {
cb();
@ -41,7 +41,7 @@ function saveDB(cb) {
}
exports.savedb = function (callback) {
saveDB(callback)
saveDB(callback);
}
exports.getVPathFiles = function (vpath, callback) {