Commit 1f46931f authored by ac32's avatar ac32

batchSeg handle race condition

parent 7944fbb3
......@@ -22,52 +22,6 @@ function anyFileInQ(processQ,leverFileList)
return null;
} // anyFileInQ
function batchResegAll(leverFileList)
{
const process=require('./process.js');
for (var i=0;i<leverFileList.length;i++) {
var leverCommand={leverFile:leverFileList[i],time:1,command:'resegAll',params:[1]};
process.addToQ(leverCommand);
}
} // batchResegAll
var batchTimer=null;
function monitorBatchList(leverFileList)
{
const process=require('./process.js');
if (null!==batchTimer) {
clearTimeout(batchTimer);
batchTimer=null;
}
if (undefined==leverFileList || 0==leverFileList.length)
return; // all done
for (var i=0;i<batchFilenames.length;i++) {
process.getLeverFileStatus(batchFilenames[i],function(leverFile,uiStatus){
if ('batchTrackPending'==uiStatus) {
var idx=batchFilenames.indexOf(leverFile);
if (idx>=0)
batchFilenames.splice(idx,1);
if (0==batchFilenames.length){
// reseg all
batchResegAll(leverFileList);
}
}
});
}
batchTimer=setTimeout(monitorBatchList,1000,leverFileList);
} // monitorBatchList
var batchFilenames=null;
function startBatchMonitor(leverFileList)
{
batchFilenames=[];
for (var i=0;i<leverFileList.length;i++)
batchFilenames.push(leverFileList[i]);
monitorBatchList(leverFileList);
} // startBatchMonitor
function batchSeg(leverFileList,fnCallback)
{
const process=require('./process.js');
......@@ -80,16 +34,12 @@ function batchSeg(leverFileList,fnCallback)
inUseFile=path.basename(inUseFile);
fnCallback(409,"leverFile :: "+inUseFile+" :: is already in the process Q -- cannot batch segment");
return;
}
let nComplete=0;
}
for (let i=0;i<leverFileList.length;i++) {
var leverDB=new LeverDB(leverFileList[i]);
leverDB.updateStatus('batch seg pending',function(){
leverDB.updateStatus('batchSeg pending',function(){
var leverCommand={leverFile:leverFileList[i],time:1,command:'batchSeg',params:[]};
process.addToQ(leverCommand);
nComplete++;
if (nComplete>=leverFileList.length)
startBatchMonitor(leverFileList);
});
}
fnCallback(200,"OK");
......
......@@ -112,16 +112,11 @@ function internalAddToQ(leverCommand)
// note - when batchSeg is active, we disallow subsequent batch segs
if (null!=batchSegFile && 'batchSeg'==leverCommand.command) {
addToProcessQ(leverCommand);
getLeverFileStatus(batchSegFile,function(leverFile,uiStatus){
if ('batchTrackPending'==uiStatus || 'idle'==uiStatus) {
batchSegFile=null;
}
});
return;
}
if ('batchSeg'==leverCommand.command) {
batchSegFile=leverCommand.leverFile;
}
}
// first, see if the leverFile is in the processQ
for (var i=0;i<inProcessQ.length;i++) {
if (undefined===inProcessQ[i].leverFile || null===inProcessQ[i].leverFile)
......@@ -338,13 +333,18 @@ function addFiletoBatchSeg(leverCommand,nSlot)
});
inProcessQ[nSlot].childProc.on('close', (code) => {
ljsLog.log('inProcessQ slot '+nSlot+' : exited with code ' + code);
var lf=inProcessQ[nSlot].leverFile;
inProcessQ[nSlot].childProc=null;
inProcessQ[nSlot].leverFile=null;
inProcessQ[nSlot].status="";
inProcessQ[nSlot].matlabPID=0; // done with the batch segment process
batchSegFile=null; // ok to start a new batch segment
checkToProcessQ();
// start a reseg on this file
var leverCommand={leverFile:lf,time:1,command:'resegAll',params:[1]};
addToQ(leverCommand);
});
} // addFiletoBatchSeg
......
......@@ -21,6 +21,8 @@ if nargin>1
[conn,CONSTANTS]=openDB(strDB);
cmd='update tblConstants set uiStatus="batchTrackPending"';
exec(conn,cmd);
cmd='DROP TABLE IF EXISTS tblCommands';
exec(conn,cmd);
close(conn);
exit;
end
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment