Add restart route for atomicity

This commit is contained in:
Girish Ramakrishnan
2019-12-20 10:29:29 -08:00
parent 887cbb0b22
commit 2692f6ef4e
6 changed files with 109 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ exports = module.exports = {
start: start,
stop: stop,
restart: restart,
exec: exec,
@@ -79,6 +80,7 @@ exports = module.exports = {
ISTATE_PENDING_BACKUP: 'pending_backup', // backup the app. this is state because it blocks other operations
ISTATE_PENDING_START: 'pending_start',
ISTATE_PENDING_STOP: 'pending_stop',
ISTATE_PENDING_RESTART: 'pending_restart',
ISTATE_ERROR: 'error', // error executing last pending_* command
ISTATE_INSTALLED: 'installed', // app is installed
@@ -1678,6 +1680,30 @@ function stop(appId, callback) {
});
}
function restart(appId, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof callback, 'function');
debug('Will restart app with id:%s', appId);
get(appId, function (error, app) {
if (error) return callback(error);
error = checkAppState(app, exports.ISTATE_PENDING_RESTART);
if (error) return callback(error);
const task = {
args: {},
values: { runState: exports.RSTATE_RUNNING }
};
addTask(appId, exports.ISTATE_PENDING_RESTART, task, function (error, result) {
if (error) return callback(error);
callback(null, { taskId: result.taskId });
});
});
}
function checkManifestConstraints(manifest) {
assert(manifest && typeof manifest === 'object');