Implement app update

Part of #34
This commit is contained in:
Girish Ramakrishnan
2014-08-24 22:18:04 -07:00
parent 4f7fa7ea45
commit d80ed67dd7
2 changed files with 38 additions and 0 deletions
+1
View File
@@ -24,6 +24,7 @@ exports = module.exports = {
ISTATE_PENDING_INSTALL: 'pending_install',
ISTATE_PENDING_CONFIGURE: 'pending_configure',
ISTATE_PENDING_UNINSTALL: 'pending_uninstall',
ISTATE_PENDING_UPDATE: 'pending_update',
ISTATE_ERROR: 'error',
ISTATE_INSTALLED: 'installed',
+37
View File
@@ -535,6 +535,39 @@ function configure(app, callback) {
});
}
function update(app, callback) {
async.series([
updateApp.bind(null, app, { installationProgress: 'Stopping app' }),
stopApp.bind(null, app),
updateApp.bind(null, app, { installationProgress: 'Deleting container' }),
deleteContainer.bind(null, app),
updateApp.bind(null, app, { installationProgress: 'Downloading manifest' }),
downloadManifest.bind(null, app),
updateApp.bind(null, app, { installationProgress: 'Downloading image' }),
downloadImage.bind(null, app),
updateApp.bind(null, app, { installationProgress: 'Creating container' }),
createContainer.bind(null, app),
runApp.bind(null, app),
// done!
function (callback) {
debug('App ' + app.id + ' updated');
updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '' }, callback);
}
], function seriesDone(error) {
if (error) {
console.error('Error updating app:', error);
return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message }, callback.bind(null, error));
}
callback(null);
});
}
function uninstall(app, callback) {
debug('uninstalling ' + app.id);
@@ -604,6 +637,10 @@ function startTask(appId, callback) {
return configure(app, callback);
}
if (app.installationState === appdb.ISTATE_PENDING_UPDATE) {
return update(app, callback);
}
if (app.installationState === appdb.ISTATE_INSTALLED) {
if (app.runState === appdb.RSTATE_PENDING_STOP) {
stopApp(app, callback);