From 33eae6e6692e77162013e6bb8143e4f667993a19 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Sun, 7 Jan 2018 18:26:37 -0800 Subject: [PATCH] Blocking non-get requests even if detached build is active --- app-backend/src/routes/UserRouter.js | 9 +++++++++ app-backend/src/user/ServiceManager.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app-backend/src/routes/UserRouter.js b/app-backend/src/routes/UserRouter.js index 5194f41..2ab0fe4 100644 --- a/app-backend/src/routes/UserRouter.js +++ b/app-backend/src/routes/UserRouter.js @@ -46,6 +46,7 @@ router.use(function (req, res, next) { return; } + const serviceManager = res.locals.user.serviceManager; // All requests except GET might be making changes to some stuff that are not designed for an asynchronous process // I'm being extra cautious. But removal of this lock mechanism requires testing and consideration of edge cases. @@ -57,6 +58,14 @@ router.use(function (req, res, next) { return; } + let activeBuildAppName = serviceManager.isAnyBuildRunning(); + if (activeBuildAppName) { + let response = new BaseApi(ApiStatusCodes.STATUS_ERROR_GENERIC, + `An active build (${activeBuildAppName}) is in progress... please wait...`); + res.send(response); + return; + } + // we don't want the same space to go under two simultaneous changes threadLockNamespace[namespace] = true; onFinished(res, function () { diff --git a/app-backend/src/user/ServiceManager.js b/app-backend/src/user/ServiceManager.js index 8297d0a..a3cf857 100644 --- a/app-backend/src/user/ServiceManager.js +++ b/app-backend/src/user/ServiceManager.js @@ -818,6 +818,23 @@ class ServiceManager { return !!this.activeBuilds[appName]; } + /** + * + * @returns the active build that it finds + */ + isAnyBuildRunning() { + + let activeBuilds = this.activeBuilds; + + for (let appName in activeBuilds) { + if (!!activeBuilds[appName]) { + return appName; + } + } + + return null; + } + getBuildStatus(appName) { const self = this; this.buildLogs[appName] = this.buildLogs[appName] || new BuildLog(BUILD_LOG_SIZE);