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

@@ -952,6 +952,27 @@ function stop(app, args, progressCallback, callback) {
});
}
function restart(app, args, progressCallback, callback) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof args, 'object');
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
async.series([
progressCallback.bind(null, { percent: 20, message: 'Restarting container' }),
docker.restartContainer.bind(null, app.id),
progressCallback.bind(null, { percent: 100, message: 'Done' }),
updateApp.bind(null, app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null })
], function seriesDone(error) {
if (error) {
debugApp(app, 'error starting app: %s', error);
return updateApp(app, { installationState: apps.ISTATE_ERROR, error: makeTaskError(error, app) }, callback.bind(null, error));
}
callback(null);
});
}
function uninstall(app, args, progressCallback, callback) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof args, 'object');
@@ -1029,6 +1050,8 @@ function run(appId, args, progressCallback, callback) {
return start(app, args, progressCallback, callback);
case apps.ISTATE_PENDING_STOP:
return stop(app, args, progressCallback, callback);
case apps.ISTATE_PENDING_RESTART:
return restart(app, args, progressCallback, callback);
default:
debugApp(app, 'apptask launched with invalid command');
return callback(new BoxError(BoxError.INTERNAL_ERROR, 'Unknown install command in apptask:' + app.installationState));