Move state enums to the model code

This commit is contained in:
Girish Ramakrishnan
2019-08-30 13:12:49 -07:00
parent b4cbf63519
commit dd0fb8292c
15 changed files with 118 additions and 156 deletions

View File

@@ -505,7 +505,7 @@ function install(app, restoreConfig, progressCallback, callback) {
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
const isInstalling = app.installationState !== appdb.ISTATE_PENDING_RESTORE; // install or clone
const isInstalling = app.installationState !== apps.ISTATE_PENDING_RESTORE; // install or clone
async.series([
// this protects against the theoretical possibility of an app being marked for install/restore from
@@ -589,11 +589,11 @@ function install(app, restoreConfig, progressCallback, callback) {
configureReverseProxy.bind(null, app),
progressCallback.bind(null, { percent: 100, message: 'Done' }),
updateApp.bind(null, app, { installationState: appdb.ISTATE_INSTALLED, health: null })
updateApp.bind(null, app, { installationState: apps.ISTATE_INSTALLED, health: null })
], function seriesDone(error) {
if (error) {
debugApp(app, 'error installing app: %s', error);
return updateApp(app, { installationState: appdb.ISTATE_ERROR, error: { message: error.message } }, callback.bind(null, error));
return updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message } }, callback.bind(null, error));
}
callback(null);
});
@@ -611,11 +611,11 @@ function backup(app, progressCallback, callback) {
}),
progressCallback.bind(null, { percent: 100, message: 'Done' }),
updateApp.bind(null, app, { installationState: appdb.ISTATE_INSTALLED, error: null })
updateApp.bind(null, app, { installationState: apps.ISTATE_INSTALLED, error: null })
], function seriesDone(error) {
if (error) {
debugApp(app, 'error backing up app: %s', error);
return updateApp(app, { installationState: appdb.ISTATE_INSTALLED, error: { message: error.message } }, callback.bind(null, error)); // return to installed state intentionally
return updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: { message: error.message } }, callback.bind(null, error)); // return to installed state intentionally
}
callback(null);
});
@@ -692,11 +692,11 @@ function configure(app, oldConfig, progressCallback, callback) {
configureReverseProxy.bind(null, app),
progressCallback.bind(null, { percent: 100, message: 'Done' }),
updateApp.bind(null, app, { installationState: appdb.ISTATE_INSTALLED, error: null, health: null })
updateApp.bind(null, app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null })
], function seriesDone(error) {
if (error) {
debugApp(app, 'error reconfiguring : %s', error);
return updateApp(app, { installationState: appdb.ISTATE_ERROR, error: { message: error.message }}, callback.bind(null, error));
return updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message }}, callback.bind(null, error));
}
callback(null);
});
@@ -798,14 +798,14 @@ function update(app, updateConfig, progressCallback, callback) {
runApp.bind(null, app, progressCallback),
progressCallback.bind(null, { percent: 100, message: 'Done' }),
updateApp.bind(null, app, { installationState: appdb.ISTATE_INSTALLED, error: null, health: null, updateTime: new Date() })
updateApp.bind(null, app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null, updateTime: new Date() })
], function seriesDone(error) {
if (error && error.backupError) {
debugApp(app, 'update aborted because backup failed', error);
updateApp(app, { installationState: appdb.ISTATE_INSTALLED, error: null, health: null }, callback.bind(null, error));
updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null }, callback.bind(null, error));
} else if (error) {
debugApp(app, 'Error updating app: %s', error);
updateApp(app, { installationState: appdb.ISTATE_ERROR, error: { message: error.message }, updateTime: new Date() }, callback.bind(null, error));
updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message }, updateTime: new Date() }, callback.bind(null, error));
} else {
if (updateConfig.skipNotification) return callback();
@@ -859,7 +859,7 @@ function uninstall(app, progressCallback, callback) {
], function seriesDone(error) {
if (error) {
debugApp(app, 'error uninstalling app: %s', error);
return updateApp(app, { installationState: appdb.ISTATE_ERROR, error: { message: error.message } }, callback.bind(null, error));
return updateApp(app, { installationState: apps.ISTATE_ERROR, error: { message: error.message } }, callback.bind(null, error));
}
callback(null);
});
@@ -875,7 +875,7 @@ function runApp(app, progressCallback, callback) {
docker.startContainer(app.containerId, function (error) {
if (error) return callback(error);
updateApp(app, { runState: appdb.RSTATE_RUNNING }, callback);
updateApp(app, { runState: apps.RSTATE_RUNNING }, callback);
});
}
@@ -889,7 +889,7 @@ function stopApp(app, progressCallback, callback) {
docker.stopContainers(app.id, function (error) {
if (error) return callback(error);
updateApp(app, { runState: appdb.RSTATE_STOPPED, health: null }, callback);
updateApp(app, { runState: apps.RSTATE_STOPPED, health: null }, callback);
});
}
@@ -906,17 +906,17 @@ function run(appId, args, progressCallback, callback) {
debugApp(app, 'startTask installationState: %s runState: %s', app.installationState, app.runState);
switch (app.installationState) {
case appdb.ISTATE_PENDING_INSTALL: return install(app, args.restoreConfig || {}, progressCallback, callback);
case appdb.ISTATE_PENDING_CONFIGURE: return configure(app, args.oldConfig, progressCallback, callback);
case appdb.ISTATE_PENDING_UNINSTALL: return uninstall(app, progressCallback, callback);
case appdb.ISTATE_PENDING_CLONE: return install(app, args.restoreConfig || {}, progressCallback, callback);
case appdb.ISTATE_PENDING_RESTORE: return install(app, args.restoreConfig || {}, progressCallback, callback);
case appdb.ISTATE_PENDING_UPDATE: return update(app, args.updateConfig, progressCallback, callback);
case appdb.ISTATE_PENDING_BACKUP: return backup(app, progressCallback, callback);
case appdb.ISTATE_INSTALLED:
case apps.ISTATE_PENDING_INSTALL: return install(app, args.restoreConfig || {}, progressCallback, callback);
case apps.ISTATE_PENDING_CONFIGURE: return configure(app, args.oldConfig, progressCallback, callback);
case apps.ISTATE_PENDING_UNINSTALL: return uninstall(app, progressCallback, callback);
case apps.ISTATE_PENDING_CLONE: return install(app, args.restoreConfig || {}, progressCallback, callback);
case apps.ISTATE_PENDING_RESTORE: return install(app, args.restoreConfig || {}, progressCallback, callback);
case apps.ISTATE_PENDING_UPDATE: return update(app, args.updateConfig, progressCallback, callback);
case apps.ISTATE_PENDING_BACKUP: return backup(app, progressCallback, callback);
case apps.ISTATE_INSTALLED:
switch (app.runState) {
case appdb.RSTATE_PENDING_STOP: return stopApp(app, progressCallback, callback);
case appdb.RSTATE_PENDING_START: return runApp(app, progressCallback, callback);
case apps.RSTATE_PENDING_STOP: return stopApp(app, progressCallback, callback);
case apps.RSTATE_PENDING_START: return runApp(app, progressCallback, callback);
default: return callback(new Error('Unknown run command in apptask:' + app.runState));
}