Commit 2b4f33e0 authored by Andrew Cohen's avatar Andrew Cohen

no more polling for process complete - server generated resegall exits on...

no more polling for process complete - server generated resegall exits on complete -- process pause and kill allr
parent 66dc7c84
......@@ -174,9 +174,8 @@ var deleteCmd = 'DELETE from tblCommands WHERE ROWID=';
gImageTime=row.time; // this points to the target frame
if (gImageTime>CONSTANTS.imageData.NumberOfFrames) {
if (gbServer) {
console.log('finished reseg');
// hmmm...this might be a place to exit the process if someone waiting...
// for now, stick around...
console.log('finished reseg -- server mode -- adios amigos!');
process.exit(0);
}
// else...
// back to the beginning -- we're done!
......@@ -279,7 +278,7 @@ function cmdLoop()
case 'setResegPause':
gResegMode='';
break;
case 'exit':
case 'exit ':
// server wants this slot...pack up our toys and go home
shutdownDB(function(){
process.exit(1);
......
......@@ -66,20 +66,28 @@
<div id='processControls'>
<i class="fa fa-cog fa-spin fa-2x fa-fw" aria-hidden="true" id='importSpinner' style="display:none;"></i>
<div style='display:block'> </div>
<button class='sbButton' onclick="processSelected(true)" id="btnProcessAll">
process all <i class="fa fa-play-circle fa-1x" aria-hidden="true"></i></button>
<button class='sbButton' onclick="processSelected(false)" id="btnProcessSelected">
process selected <i class="fa fa-play-circle-o fa-1x" aria-hidden="true"></i></button>
<button class='sbButton' onclick="removeAllFromQ()" id="btnRemoveQ" tabindex="3">
remove all from queue <i class="fa fa-minus-circle fa-1x" aria-hidden="true"></i> </button>
<button class='sbButton' onclick="eraseAllSelected()" id="btnEraseAll" tabindex="4">
erase all from selected <i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
<i id="imgBtnResegAll" class="fa fa-remove fa-1x" aria-hidden="true"></i></button>
<button class='sbButton' onclick="pauseAll(false)" id="btnPause" style="display:none">
pause all <i class="fa fa-pause-circle-o fa-1x" aria-hidden="true"></i></button>
<button class='sbButton' onclick="eraseAllSelected()" id="btnEraseAll" tabindex="4">
erase all from selected <i id="imgBtnResegAll" class="fa fa-remove fa-1x" aria-hidden="true"></i></button>
<button class='sbButton' onclick="pauseAll(true)" id="btnForceReset" tabindex="7">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
force reboot analyze processes <i class="fa fa-power-off <fa-1></fa-1>x" aria-hidden="true"></i></button>
<div style='display:block'> <h2>in processs</h2>
<table id="tableProcess"></table>
</div>
<div style='display:block'> <h2> waiting to be processed </h2>
<table id="tableQ"></table>
<table id="tableQ"></table>
</div>
</div>
......
......@@ -43,8 +43,45 @@ if (IS_NODE) {
}
function removeAllFromQ()
{
// todo! called from ExperimentWindow.html
} // removeAllFromQ
function pauseAll(bKill)
{
if (bKill) {
var result = window.confirm('reset on running processes may leave data corrupt -- not undoable\n\n'+
'best practice is to eraseAll from any reset running processes. OK to continue, CANCEL to abort.');
if (result!==true)
return;
}
var btnPause=document.getElementById('btnPause');
btnPause.style.display="none";
if (IS_NODE) {
pauseOrKillAll(bKill);
updateProcess();
}
else {
if (bKill) {
cmd=gServerURL+'pauseProcessAll';
}
else {
cmd=gServerURL+'killProcessAll';
}
editSendServerCommand(cmd,function(){},pauseAll,[]);
}
} // pauseAll
function processSelected(bAddAll)
{
var btnPause=document.getElementById('btnPause');
btnPause.style.display="";
for (var n=0;n<gExperiments.length;n++) {
var view=gLeverFileMap.get(gExperiments[n].leverFile);
if (view.bChecked || bAddAll) {
......@@ -96,7 +133,10 @@ function buildProcessTables(Q)
else
cacheInProcessQ=Q.inProcessQ;
var bAllIdle=true;
for (var i=0;i<Q.inProcessQ.length;i++) {
if ('empty'===Q.inProcessQ[i].leverFile)
continue;
var iRow=findProcessRow(tbl,Q.inProcessQ[i].nSlot);
var row=tbl.insertRow(iRow);
var leverFile=Q.inProcessQ[i].leverFile;
......@@ -108,19 +148,18 @@ function buildProcessTables(Q)
row.nSlot=Q.inProcessQ[i].nSlot;
row.innerHTML='<td>+'+(Q.inProcessQ[i].nSlot)+': </td><td class="processRow">'+leverFile+'</td>';
if (status.length>0) {
var playPauseButton='<button class="sbButton" onclick=manageProcess('+i+',0)>'+
'<i class="fa fa-pause fa-1x" aria-hidden="true"> </i></button>';
if ('idle'==status)
playPauseButton='<button class="sbButton" onclick=manageProcess('+i+',0)>'+
'<i class="fa fa-play fa-1x" aria-hidden="true"> </i></button>';
var killButton='<button class="sbButton" onclick=manageProcess('+i+',1)>'+
'<i class="fa fa-power-off fa-1x" aria-hidden="true"> </i></button>';
row.innerHTML+='<td class="processRow">'+status+'</td> '+
'<td class="processRow">'+playPauseButton+'</td><td>'+killButton+'</td>';
if ('idle'!=status)
bAllIdle=false;
row.innerHTML+='<td class="processRow">'+status+'</td>';
}
}
var btnPause=document.getElementById('btnPause');
if (bAllIdle) {
btnPause.style.display="none";
}
else {
btnPause.style.display="";
}
var tbl=document.getElementById('tableQ');
tbl.innerHTML='';
var i=0;
......
......@@ -132,7 +132,11 @@
Re-seg all <i id="imgBtnResegAll" class="fa fa-play fa-1x" aria-hidden="true"></i></button>
<button class='sbButton' onclick='editReseg("resegNext")' id="btnResegForward" tabindex="5">
Re-seg next <i class="fa fa-step-forward <fa-1></fa-1>x" aria-hidden="true"></i> </button>
<h2> edit status </h2>
<buton class='sbButton' onclick="restartAnalysis();" id="btnRestartAnalysis" tabindex="7">
force reboot analyze processes <i class="fa fa-power-off <fa-1></fa-1>x" aria-hidden="true"></i></button>
<h2> edit status </h2>
<select id='editStatus'> <option>status: idle</option></select>
<div id="editQ">
......@@ -143,8 +147,7 @@
<br>
<button class='sbButton' onclick="restartAnalysis();" id="btnRestartAnalysis" tabindex="7">
force reboot analyze processes <i class="fa fa-power-off <fa-1></fa-1>x" aria-hidden="true"></i></button>
</div>
<table id='editList' ></table>
</div>
......
......@@ -51,32 +51,10 @@ function checkToProcessQ()
}
}
if (toProcessQ.length>0) {
const LeverDB=require('./lever.js');
// look for an idle process to kick out
getQ(function(Q){
var statusQ=Q.inProcessQ;
for (var i=0;i<statusQ.length;i++) {
if ('idle'==statusQ[i].status) {
var quitCommand={leverFile:statusQ[i].leverFile,command:'exit'};
var quitDB=new LeverDB(statusQ[i].leverFile);
quitDB.addCommandToDB(quitCommand,function(){
quitDB.close();
});
}
}
},5,false);
setTimeout(checkToProcessQ,250);
}
} // checkToProcessQ
function addToProcessQ(leverCommand)
{
if (0===toProcessQ.length) {
// Q is empty -- start watchdog timer
setTimeout(checkToProcessQ,250);
}
toProcessQ.push(leverCommand);
} // addToProcessQ
......@@ -177,12 +155,6 @@ function addToQ(leverCommand)
} // addToQ
function removeAllFromQ()
{
toProcessQ=[];
updateProcess();
} // removeAllFromQ
// nSlot is the index into the inProcessQ -- zero to NPROCESS
function addFileToProcess(leverCommand,nSlot)
{
......@@ -225,11 +197,12 @@ function addFileToProcess(leverCommand,nSlot)
inProcessQ[nSlot].childProc=null;
inProcessQ[nSlot].leverFile=null;
inProcessQ[nSlot].status="";
checkToProcessQ();
});
} // addFileToProcess
var Q;
var cacheQ;
// hrInterval is how stale a Q you will tolerate, in seconds (!)
function getQ(fnCallback,hrInterval,bSanitizeFileName)
{
......@@ -242,33 +215,33 @@ function getQ(fnCallback,hrInterval,bSanitizeFileName)
if (undefined===bSanitizeFileName)
bSanitizeFileName=true;
if (undefined!==Q) {
if (undefined!==cacheQ && null!==cacheQ) {
var hrnow=process.hrtime();
if ( ( hrnow[0]-Q.hrtime[0] + 1e-9*(hrnow[1]-Q.hrtime[1]) ) < hrInterval ) {
// Q is fresh enough, send it
fnCallback(Q);
if ( ( hrnow[0]-cacheQ.hrtime[0] + 1e-9*(hrnow[1]-cacheQ.hrtime[1]) ) < hrInterval ) {
// cacheQ is fresh enough, send it
fnCallback(cacheQ);
return;
}
// if (0==Q.inProcessQ.length){
// // we have a Q but empty inProcessQ -- another getQ is pending
// fnCallback(Q);
// if (0==cacheQ.inProcessQ.length){
// // we have a cacheQ but empty inProcessQ -- another getQ is pending
// fnCallback(cacheQ);
// return;
// }
}
// else freshen the Q status
Q={};
// else freshen the cacheQ status
cacheQ={};
Q.hrtime=process.hrtime();
cacheQ.hrtime=process.hrtime();
var copyToProcessQ=[];
for (var i=0;i<toProcessQ.length;i++){
copyToProcessQ[i]={command:toProcessQ[i].command,leverFile:toProcessQ[i].leverFile,ID:toProcessQ[i].ID,
time:toProcessQ[i].time};
}
Q.toProcessQ=copyToProcessQ;
cacheQ.toProcessQ=copyToProcessQ;
Q.inProcessQ=[];
cacheQ.inProcessQ=[];
// initialize the Q if needed
// initialize the cacheQ if needed
if (undefined===inProcessQ) {
initInProcessQ();
}
......@@ -287,16 +260,16 @@ function getQ(fnCallback,hrInterval,bSanitizeFileName)
processStatus={leverFile:leverFile,status:status,ID:ID,nSlot:i};
statusQ.push(processStatus);
if (inProcessQ.length===statusQ.length) {
Q.inProcessQ=statusQ;
fnCallback(Q);
cacheQ.inProcessQ=statusQ;
fnCallback(cacheQ);
}
});
}
else {
statusQ.push({leverFile:'empty',status:''});
if (inProcessQ.length===statusQ.length) {
Q.inProcessQ=statusQ;
fnCallback(Q);
cacheQ.inProcessQ=statusQ;
fnCallback(cacheQ);
}
}
......@@ -323,9 +296,30 @@ function removeID(editID)
gCommandMap.delete(editID);
} // removeID
function pauseOrKillAll(bKill)
{
toProcessQ=[];
for (var i=0;i<inProcessQ.length;i++) {
if (bKill) {
inProcessQ[i].childProc.kill();
}
else {
// pause gets put right into Q
var leverCommand={leverFile:inProcessQ[i].leverFile,command:'resegPause',time:1};
const LeverDB=require('./lever.js');
var leverDB=new LeverDB(leverCommand.leverFile);
leverDB.addCommandToDB(leverCommand,function(){
leverDB.close();
});
}
}
} // processPauseAll
if (('undefined'===typeof IS_NODE) || (IS_NODE)) {
module.exports.getQ=getQ;
module.exports.addToQ=addToQ;
module.exports.getStatus=getStatus;
module.exports.removeID=removeID;
module.exports.pauseOrKillAll=pauseOrKillAll;
}
......@@ -148,7 +148,18 @@ app.post('/:LEVER/createCells/',checkLWT, jsonParser,function(req,res) {
});
app.post('/pauseProcessAll/',checkLWT, function(req,res) {
const process=require('./leverjs/process.js');
process.pauseOrKillAll(false);
res.send('ok');
});
app.post('/killProcessAll/',checkLWT, function(req,res) {
const process=require('./leverjs/process.js');
process.pauseOrKillAll(true);
res.send('ok');
});
app.get('/processQ', function(req,res) {
const process=require('./leverjs/process.js');
var Q=process.getQ(function(Q) {
......
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