Refactor configure event handling into onConfigured event

This commit is contained in:
Girish Ramakrishnan
2017-01-07 23:31:29 -08:00
parent d0ea1a4cf4
commit 18f6c4f2cd

View File

@@ -122,9 +122,6 @@ CloudronError.SELF_UPGRADE_NOT_SUPPORTED = 'Self upgrade not supported';
function initialize(callback) {
assert.strictEqual(typeof callback, 'function');
exports.events.on(exports.EVENT_CONFIGURED, addDnsRecords);
exports.events.on(exports.EVENT_CONFIGURED, configureAdmin);
if (!fs.existsSync(paths.FIRST_RUN_FILE)) {
debug('initialize: installing app bundle on first run');
process.nextTick(installAppBundle);
@@ -137,11 +134,18 @@ function initialize(callback) {
function uninitialize(callback) {
assert.strictEqual(typeof callback, 'function');
exports.events.removeListener(exports.EVENT_CONFIGURED, addDnsRecords);
callback(null);
}
function onConfigured(callback) {
callback = callback || NOOP_CALLBACK;
async.series([
addDnsRecords,
configureAdmin
], callback);
}
function getConfigStateSync() {
return gConfigState;
}
@@ -175,6 +179,7 @@ function syncConfigState(callback) {
if (configured) {
gConfigState.configured = true;
exports.events.emit(exports.EVENT_CONFIGURED);
onConfigured();
} else {
settings.events.once(settings.DNS_CONFIG_KEY, function () { syncConfigState(); }); // check again later
}