refactor: remove config namespaces

This commit is contained in:
NGPixel
2018-05-28 14:46:55 -04:00
parent b1499d1d64
commit 416755f17a
27 changed files with 556 additions and 283 deletions

View File

@@ -1,89 +1,53 @@
const _ = require('lodash')
const cluster = require('cluster')
const Promise = require('bluebird')
/* global WIKI */
module.exports = {
numWorkers: 1,
workers: [],
init() {
if (cluster.isMaster) {
WIKI.logger.info('=======================================')
WIKI.logger.info('= Wiki.js =============================')
WIKI.logger.info('=======================================')
async init() {
WIKI.logger.info('=======================================')
WIKI.logger.info('= Wiki.js =============================')
WIKI.logger.info('=======================================')
WIKI.redis = require('./redis').init()
WIKI.queue = require('./queue').init()
WIKI.db = require('./db').init()
WIKI.redis = require('./redis').init()
WIKI.queue = require('./queue').init()
this.setWorkerLimit()
this.bootMaster()
} else {
this.bootWorker()
}
await this.preBootMaster()
this.bootMaster()
},
/**
* Pre-Master Boot Sequence
*/
preBootMaster() {
return Promise.mapSeries([
() => { return WIKI.db.onReady },
() => { return WIKI.configSvc.loadFromDb() },
() => { return WIKI.queue.clean() }
], fn => { return fn() })
async preBootMaster() {
try {
await WIKI.db.onReady
await WIKI.configSvc.loadFromDb()
await WIKI.queue.clean()
} catch (err) {
WIKI.logger.error(err)
process.exit(1)
}
},
/**
* Boot Master Process
*/
bootMaster() {
this.preBootMaster().then(sequenceResults => {
if (_.every(sequenceResults, rs => rs === true) && WIKI.config.configMode !== 'setup') {
this.postBootMaster()
} else {
WIKI.logger.info('Starting configuration manager...')
async bootMaster() {
try {
if (WIKI.config.setup) {
WIKI.logger.info('Starting setup wizard...')
require('../setup')()
} else {
await require('../master')()
this.postBootMaster()
}
return true
}).catch(err => {
} catch (err) {
WIKI.logger.error(err)
process.exit(1)
})
}
},
/**
* Post-Master Boot Sequence
*/
async postBootMaster() {
await require('../master')()
WIKI.queue.start()
cluster.on('exit', (worker, code, signal) => {
if (!global.DEV) {
WIKI.logger.info(`Background Worker #${worker.id} was terminated.`)
}
})
},
/**
* Boot Worker Process
*/
bootWorker() {
WIKI.logger.info(`Background Worker #${cluster.worker.id} is initializing...`)
require('../worker')
},
/**
* Spawn new Worker process
*/
spawnWorker() {
this.workers.push(cluster.fork())
},
/**
* Set Worker count based on config + system capabilities
*/
setWorkerLimit() {
const numCPUs = require('os').cpus().length
this.numWorkers = (WIKI.config.workers > 0) ? WIKI.config.workers : numCPUs
if (this.numWorkers > numCPUs) {
this.numWorkers = numCPUs
}
await WIKI.auth.activateStrategies()
await WIKI.queue.start()
}
}