Use task API for app configure

This commit is contained in:
Girish Ramakrishnan
2019-08-26 21:36:18 -07:00
parent 96d19f59a4
commit 824f00d1e8
2 changed files with 21 additions and 25 deletions
+19 -20
View File
@@ -603,7 +603,7 @@ function install(app, progressCallback, callback) {
], function seriesDone(error) {
if (error) {
debugApp(app, 'error installing app: %s', error);
return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message }, callback.bind(null, error));
return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message, taskId: null }, callback.bind(null, error));
}
callback(null);
});
@@ -632,8 +632,9 @@ function backup(app, callback) {
}
// note that configure is called after an infra update as well
function configure(app, callback) {
function configure(app, progressCallback, callback) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
// oldConfig can be null during an infra update
@@ -641,7 +642,7 @@ function configure(app, callback) {
const dataDirChanged = app.oldConfig && (app.oldConfig.dataDir !== app.dataDir);
async.series([
updateApp.bind(null, app, { installationProgress: '10, Cleaning up old install' }),
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
unconfigureReverseProxy.bind(null, app),
removeCollectdProfile.bind(null, app),
removeLogrotateConfig.bind(null, app),
@@ -656,23 +657,23 @@ function configure(app, callback) {
reserveHttpPort.bind(null, app),
updateApp.bind(null, app, { installationProgress: '20, Downloading icon' }),
progressCallback.bind(null, { percent: 20, message: 'Downloading icon' }),
downloadIcon.bind(null, app),
updateApp.bind(null, app, { installationProgress: '30, Registering subdomain' }),
progressCallback.bind(null, { percent: 30, message: 'Registering subdomain' }),
registerSubdomain.bind(null, app, !locationChanged /* overwrite */), // if location changed, do not overwrite to detect conflicts
updateApp.bind(null, app, { installationProgress: '35, Registering alternate domains'}),
progressCallback.bind(null, { percent: 35, message: 'Registering alternate domains' }),
registerAlternateDomains.bind(null, app, true /* overwrite */), // figure out when to overwrite
updateApp.bind(null, app, { installationProgress: '40, Downloading image' }),
progressCallback.bind(null, { percent: 40, message: 'Downloading image' }),
downloadImage.bind(null, app.manifest),
updateApp.bind(null, app, { installationProgress: '45, Ensuring app data directory' }),
progressCallback.bind(null, { percent: 45, message: 'Ensuring app data directory' }),
createAppDir.bind(null, app),
// re-setup addons since they rely on the app's fqdn (e.g oauth)
updateApp.bind(null, app, { installationProgress: '50, Setting up addons' }),
progressCallback.bind(null, { percent: 50, message: 'Setting up addons' }),
addons.setupAddons.bind(null, app, app.manifest.addons),
// migrate dataDir
@@ -682,32 +683,29 @@ function configure(app, callback) {
migrateDataDir(app, app.oldConfig.dataDir, next);
},
updateApp.bind(null, app, { installationProgress: '60, Creating container' }),
progressCallback.bind(null, { percent: 60, message: 'Creating container' }),
createContainer.bind(null, app),
updateApp.bind(null, app, { installationProgress: '65, Setting up logrotate config' }),
progressCallback.bind(null, { percent: 65, message: 'Setting up logrotate config' }),
addLogrotateConfig.bind(null, app),
updateApp.bind(null, app, { installationProgress: '70, Add collectd profile' }),
progressCallback.bind(null, { percent: 70, message: 'Add collectd profile' }),
addCollectdProfile.bind(null, app),
runApp.bind(null, app),
updateApp.bind(null, app, { installationProgress: '80, Waiting for DNS propagation' }),
progressCallback.bind(null, { percent: 80, message: 'Waiting for DNS propagation' }),
exports._waitForDnsPropagation.bind(null, app),
updateApp.bind(null, app, { installationProgress: '90, Configuring reverse proxy' }),
progressCallback.bind(null, { percent: 90, message: 'Configuring reverse proxy' }),
configureReverseProxy.bind(null, app),
// done!
function (callback) {
debugApp(app, 'configured');
updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '', health: null }, callback);
}
progressCallback.bind(null, { percent: 100, message: 'Done' }),
updateApp.bind(null, app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '', health: null, taskId: null })
], function seriesDone(error) {
if (error) {
debugApp(app, 'error reconfiguring : %s', error);
return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message }, callback.bind(null, error));
return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message, taskId: null }, callback.bind(null, error));
}
callback(null);
});
@@ -967,6 +965,7 @@ function run(appId, progressCallback, callback) {
switch (app.installationState) {
case appdb.ISTATE_PENDING_INSTALL: return install(app, progressCallback, callback);
case appdb.ISTATE_PENDING_CONFIGURE: return configure(app, progressCallback, callback);
default:
debugApp(app, 'apptask launched with invalid command');