Skip to content

Commit

Permalink
try catch around docker.command("ps");
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Feb 12, 2025
1 parent 07f08ee commit 7e03553
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
3 changes: 2 additions & 1 deletion data/processes/addNumbers/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ export async function launch(process_, job, isAsync, parameters, callback) {
let result = {};
result.id = key;

if ((output.schema.type = "number")) result.value = Number(child.stdout);
if ((output.schema.type = "number"))
result.value = Number(child.stdout);

// TODO: what to do??
//if (parameterOutput.transmissionMode == "value") content = result;
Expand Down
37 changes: 20 additions & 17 deletions data/processes/echoService/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function launch(process_, job, isAsync, parameters, callback) {
return callback(
{ code: 400, description: `addNumbersInContainer run only async` },
undefined
);
)
}

job.status = "running"; // accepted, successful, failed, dismissed
Expand Down Expand Up @@ -66,22 +66,25 @@ export async function launch(process_, job, isAsync, parameters, callback) {
});
*/

// get running containers
let data = await docker.command("ps");
// is our container already running?
const notFound =
data.containerList.findIndex((element) => element.image == containerName) <
0;

if (notFound) {
const command = `run -d -p ${port}:80 ${containerName}`;

let result = await docker.command(command);
console.log(result);
// give container time to settle
await new Promise((r) => setTimeout(r, 1000));
} else {
console.log(`Container ${containerName} already running. Good.`);
try {
// get running containers
let data = await docker.command("ps")

// is our container already running?
const notFound = data.containerList.findIndex((element) => element.image == containerName) < 0;
if (notFound) {
const command = `run -d -p ${port}:80 ${containerName}`;

let result = await docker.command(command);
console.log(result);
// give container time to settle
await new Promise((r) => setTimeout(r, 1000));
} else {
console.log(`Container ${containerName} already running. Good.`);
}
}
catch (err) {
return callback({ code: 400, description: err.message }, undefined)
}

let content = {};
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/processes/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export function post(req, res) {
prefer,
function (err, content, location) {
if (err) {
res
.status(err.code)
.json({ code: err.code, description: err.description });
res.status(err.code)
.json({ code: err.code, description: err.description });
return;
}

Expand Down

0 comments on commit 7e03553

Please sign in to comment.