From a502037b4d026d7a9e375e84e3c368f41b7be51c Mon Sep 17 00:00:00 2001 From: Robin Leber <rleber98@gmail.com> Date: Tue, 11 Jun 2024 15:03:05 +0200 Subject: [PATCH] Feat: NOT WORKING - Scaling --- src/functions/helperFunctions.js | 24 ++++++++++++++++++++++++ src/routes/deployRouter.js | 14 +++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/functions/helperFunctions.js b/src/functions/helperFunctions.js index 4e5b0b6..7250318 100644 --- a/src/functions/helperFunctions.js +++ b/src/functions/helperFunctions.js @@ -194,6 +194,29 @@ const clearArchitecture = async () => { } }; +const scaleOut = async (id) => { + try { + const dataFilePath = path.resolve( + __dirname, + "../../customCodeDatabase.json" + ); + const customCodes = await getCustomCodes(); + const codeToScale = customCodes.find((code) => code.id === id); + const scaledCode = JSON.parse(JSON.stringify(codeToScale)); + scaledCode.isScaled = true; + scaledCode.id; + customCodes.push(scaledCode); + await fs.writeFile( + dataFilePath, + JSON.stringify(customCodes, null, 2), + "utf8" + ); + } catch (err) { + console.error(err); + throw err; + } +}; + module.exports = { emptyDockerJS, fillDockerJS, @@ -204,4 +227,5 @@ module.exports = { clearArchitecture, stopArchitecture, restartArchitecture, + scaleOut, }; diff --git a/src/routes/deployRouter.js b/src/routes/deployRouter.js index 2f34cb6..d6a1516 100644 --- a/src/routes/deployRouter.js +++ b/src/routes/deployRouter.js @@ -4,6 +4,7 @@ const { stopArchitecture, restartArchitecture, clearArchitecture, + scaleOut, } = require("../functions/helperFunctions"); const deployRouter = express.Router(); @@ -38,7 +39,7 @@ deployRouter.post("/restart", async (req, res) => { } }); -deployRouter.get("/clearArchitecture", async (rey, res) => { +deployRouter.get("/clearArchitecture", async (req, res) => { try { await clearArchitecture(); res.status(200).json({ message: "Docker leeren erfoglreich" }); @@ -48,4 +49,15 @@ deployRouter.get("/clearArchitecture", async (rey, res) => { } }); +deployRouter.post("/scaleOut", async (req, res) => { + try { + const { codeId } = req.body; + await scaleOut(codeId); + res.status(200).json({ message: "Scale Out erfolgreich" }); + } catch (e) { + console.error(e); + res.status(500).json({ message: "Scale Out fehlgeschlagen" }); + } +}); + module.exports = deployRouter; -- GitLab