diff --git a/src/tasks.js b/src/tasks.js index d4446f328..952fa8a55 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -1,20 +1,20 @@ 'use strict'; exports = module.exports = { - get: get, - add: add, - update: update, - setCompleted: setCompleted, - setCompletedByType: setCompletedByType, - listByTypePaged: listByTypePaged, + get, + add, + update, + setCompleted, + setCompletedByType, + listByTypePaged, - getLogs: getLogs, + getLogs, - startTask: startTask, - stopTask: stopTask, - stopAllTasks: stopAllTasks, + startTask, + stopTask, + stopAllTasks, - removePrivateFields: removePrivateFields, + removePrivateFields, // task types. if you add a task here, fill up the function table in taskworker and dashboard client.js TASK_APP: 'app', diff --git a/src/updater.js b/src/updater.js index b81d3918c..680866565 100644 --- a/src/updater.js +++ b/src/updater.js @@ -23,6 +23,7 @@ var apps = require('./apps.js'), paths = require('./paths.js'), safe = require('safetydance'), semver = require('semver'), + settings = require('./settings.js'), shell = require('./shell.js'), tasks = require('./tasks.js'), updateChecker = require('./updatechecker.js'); @@ -219,21 +220,27 @@ function updateToLatest(options, auditSource, callback) { error = locker.lock(locker.OP_BOX_UPDATE); if (error) return callback(new BoxError(BoxError.BAD_STATE, `Cannot update now: ${error.message}`)); - tasks.add(tasks.TASK_UPDATE, [ boxUpdateInfo, options ], function (error, taskId) { + settings.getBackupConfig(function (error, backupConfig) { if (error) return callback(error); - eventlog.add(eventlog.ACTION_UPDATE, auditSource, { taskId, boxUpdateInfo }); + const memoryLimit = 'memoryLimit' in backupConfig ? Math.max(backupConfig.memoryLimit/1024/1024, 400) : 400; - tasks.startTask(taskId, { timeout: 20 * 60 * 60 * 1000 /* 20 hours */ }, (error) => { - locker.unlock(locker.OP_BOX_UPDATE); + tasks.add(tasks.TASK_UPDATE, [ boxUpdateInfo, options ], function (error, taskId) { + if (error) return callback(error); - debug('Update failed with error', error); + eventlog.add(eventlog.ACTION_UPDATE, auditSource, { taskId, boxUpdateInfo }); - const timedOut = error.code === tasks.ETIMEOUT; - eventlog.add(eventlog.ACTION_UPDATE_FINISH, auditSource, { taskId, errorMessage: error.message, timedOut }); + tasks.startTask(taskId, { timeout: 20 * 60 * 60 * 1000 /* 20 hours */, nice: 15, memoryLimit }, (error) => { + locker.unlock(locker.OP_BOX_UPDATE); + + debug('Update failed with error', error); + + const timedOut = error.code === tasks.ETIMEOUT; + eventlog.add(eventlog.ACTION_UPDATE_FINISH, auditSource, { taskId, errorMessage: error.message, timedOut }); + }); + + callback(null, taskId); }); - - callback(null, taskId); }); }); }