diff --git a/src/apps.js b/src/apps.js index 0c57ea282..39d9c2faf 100644 --- a/src/apps.js +++ b/src/apps.js @@ -63,6 +63,7 @@ exports = module.exports = { getDataDir, getIconPath, + getMemoryLimit, downloadFile, uploadFile, @@ -445,6 +446,20 @@ function getIconPath(app, options, callback) { callback(new BoxError(BoxError.NOT_FOUND, 'No icon')); } +function getMemoryLimit(app) { + assert.strictEqual(typeof app, 'object'); + + let memoryLimit = app.memoryLimit || app.manifest.memoryLimit || 0; + + if (memoryLimit === -1) { // unrestricted + memoryLimit = 0; + } else if (memoryLimit === 0 || memoryLimit < constants.DEFAULT_MEMORY_LIMIT) { // ensure we never go below minimum (in case we change the default) + memoryLimit = constants.DEFAULT_MEMORY_LIMIT; + } + + return memoryLimit; +} + function postProcess(app, domainObjectMap) { let result = {}; for (let portName in app.portBindings) { diff --git a/src/docker.js b/src/docker.js index 24d3ee53e..2a00d9115 100644 --- a/src/docker.js +++ b/src/docker.js @@ -34,6 +34,7 @@ exports = module.exports = { }; var addons = require('./addons.js'), + apps = require('./apps.js'), async = require('async'), assert = require('assert'), BoxError = require('./boxerror.js'), @@ -268,14 +269,7 @@ function createSubcontainer(app, name, cmd, options, callback) { let appEnv = []; Object.keys(app.env).forEach(function (name) { appEnv.push(`${name}=${app.env[name]}`); }); - // first check db record, then manifest - var memoryLimit = app.memoryLimit || manifest.memoryLimit || 0; - - if (memoryLimit === -1) { // unrestricted - memoryLimit = 0; - } else if (memoryLimit === 0 || memoryLimit < constants.DEFAULT_MEMORY_LIMIT) { // ensure we never go below minimum (in case we change the default) - memoryLimit = constants.DEFAULT_MEMORY_LIMIT; - } + let memoryLimit = apps.getMemoryLimit(app); // give scheduler tasks twice the memory limit since background jobs take more memory // if required, we can make this a manifest and runtime argument later