Skip to content

Commit

Permalink
fix: synched queries of start/stop and GPU list
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas Osman committed Aug 25, 2021
1 parent a5ca8c7 commit 0910040
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"open": "^7.2.1"
},
"devDependencies": {}
}
}
4 changes: 2 additions & 2 deletions src/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ module.exports = {
}
});
},
stContainer: function(containerName, gpu) {
stContainer: function(containerName, gpu, callback) {
commandName = editName(containerName);
model.getContainer(containerName, gpu, function(query) {
if (query) {
console.log(query);
if (query.isOnline) {
cmd("docker stop " + commandName);
model.setContainerOff(containerName, gpu);
Expand All @@ -150,6 +149,7 @@ module.exports = {
console.log("docker start " + commandName);
}
}
return callback("Done");
});
}
};
36 changes: 21 additions & 15 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,27 @@ app.get('/signout', function(req, res) {
});

app.post("/auth", function(req, res) {
req.session.currGPU = String(ip.address());
controller.containersJSON(function(wsInfo) {
req.session.GPUs = wsInfo["gpu_address"].filter((x, i) => i === wsInfo["gpu_address"].indexOf(x));
});
console.log(req.session.currGPU);
req.session.username = req.body.username;
var password = req.body.password;
controller.auth(req.session.username, password, function(loggedin) {
req.session.wrongUserPass = loggedin.wrongUserPass;
req.session.adminLoggedIn = loggedin.adminLoggedIn;
req.session.loggedin = !req.session.wrongUserPass;
if (req.session.loggedin) {
res.redirect("/sysInfo");
} else {
res.redirect("/");
if (req.session.GPUs) {
req.session.currGPU = req.session.GPUs[0];
}
else {
req.session.currGPU = String(ip.address());
}
console.log(req.session.currGPU);
req.session.username = req.body.username;
var password = req.body.password;
controller.auth(req.session.username, password, function(loggedin) {
req.session.wrongUserPass = loggedin.wrongUserPass;
req.session.adminLoggedIn = loggedin.adminLoggedIn;
req.session.loggedin = !req.session.wrongUserPass;
if (req.session.loggedin) {
res.redirect("/sysInfo");
} else {
res.redirect("/");
}
});
});
});

Expand Down Expand Up @@ -138,7 +143,8 @@ app.post("/deleteWorkspace", function(req, res) {

app.post("/stWorkspace", function(req, res) {
var containerToSt = req.body.workspaceName;
controller.stContainer(containerToSt, String(ip.address()));
res.redirect("/workspaces/" + req.session.currGPU);
controller.stContainer(containerToSt, String(ip.address()), function(done) {
res.redirect("/workspaces/" + req.session.currGPU);
});
});
app.listen(3000);

0 comments on commit 0910040

Please sign in to comment.