Blocking non-get requests even if detached build is active

This commit is contained in:
Kasra Bigdeli
2018-01-07 18:26:37 -08:00
parent cfbb386987
commit 33eae6e669
2 changed files with 26 additions and 0 deletions
+9
View File
@@ -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 () {
+17
View File
@@ -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);