Skip to content

Commit

Permalink
accumulate output in local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Pop John committed Aug 6, 2024
1 parent c375b51 commit 9ca0bd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
11 changes: 7 additions & 4 deletions backend/src/facades/commandExecutionFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ function getConnectionStatus() {
*/
function executeCommand(cmd, onData, onEnd = () => {}, onError = () => {}, accumulateOutput = false) {
if (process.env.CONNECTION_TYPE === CONNECTION_TYPE.LOCAL) {
// RUN ON LOCAL MACHINE
const child = exec(cmd);
let stdoutData = '';
let stderrData = '';

child.stdout.on('data', (data) => {
onData(data.toString());
if (accumulateOutput) {
stdoutData += data.toString();
} else {
onData(data.toString());
}
});

child.stderr.on('data', (data) => {
Expand All @@ -64,12 +68,11 @@ function executeCommand(cmd, onData, onEnd = () => {}, onError = () => {}, accum
const errorMessage = `Process exited with code ${code}` + (stderrData ? `: ${stderrData}` : '');
onError(errorMessage);
} else {
onEnd();
onEnd(accumulateOutput ? stdoutData : undefined);
}
});

child.on('error', (err) => {
// Handling process spawning errors
onError(`Failed to start subprocess: ${err.message}`);
});
} else {
Expand Down
17 changes: 5 additions & 12 deletions backend/src/router/modelsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,18 @@ router.get('/models-list/:type', checkSshConnection, (req, res) => {
isTrained: files.includes(modelName)
}));

res.status(OK).send(modelsWithTrainingInfo);
},
() => {
const modelsAreNotTrained = models.map((modelName) => ({
name: modelName,
isTrained: false
}));

res.status(OK).send(modelsAreNotTrained);
return res.status(OK).send(modelsWithTrainingInfo);
},
() => {},
(error) => {
if (error.includes('No such file or directory')) {
if (!error || error.includes('No such file or directory')) {
const modelsWithTrainingInfo = models.map((modelName) => ({
name: modelName,
isTrained: false
}));
res.status(OK).send(modelsWithTrainingInfo);
return res.status(OK).send(modelsWithTrainingInfo);
} else {
res.status(INTERNAL_SERVER_ERROR).send({ error: `Error listing model checkpoint files: ${error}` });
return res.status(INTERNAL_SERVER_ERROR).send({ error: `Error listing model checkpoint files: ${error}` });
}
}
);
Expand Down

0 comments on commit 9ca0bd0

Please sign in to comment.