wikijs-fork/server/worker.js

63 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-08-03 03:47:11 +00:00
const Promise = require('bluebird')
2017-07-29 21:33:08 +00:00
/* global WIKI */
2017-08-03 03:47:11 +00:00
module.exports = Promise.join(
WIKI.db.onReady,
WIKI.configSvc.loadFromDb(['features', 'logging', 'site', 'uploads'])
2017-08-03 03:47:11 +00:00
).then(() => {
const path = require('path')
WIKI.REPOPATH = path.resolve(WIKI.ROOTPATH, WIKI.config.paths.repo)
WIKI.DATAPATH = path.resolve(WIKI.ROOTPATH, WIKI.config.paths.data)
WIKI.UPLTEMPPATH = path.join(WIKI.DATAPATH, 'temp-upload')
2017-08-03 03:47:11 +00:00
// ----------------------------------------
// Load global modules
// ----------------------------------------
WIKI.lang = require('i18next')
2017-08-03 03:47:11 +00:00
// ----------------------------------------
// Localization Engine
// ----------------------------------------
2017-05-04 02:10:12 +00:00
2017-08-03 03:47:11 +00:00
const i18nBackend = require('i18next-node-fs-backend')
WIKI.lang.use(i18nBackend).init({
2017-08-03 03:47:11 +00:00
load: 'languageOnly',
ns: ['common', 'admin', 'auth', 'errors'],
2017-08-03 03:47:11 +00:00
defaultNS: 'common',
saveMissing: false,
preload: [WIKI.config.lang],
lng: WIKI.config.lang,
2017-08-03 03:47:11 +00:00
fallbackLng: 'en',
backend: {
loadPath: path.join(WIKI.SERVERPATH, 'locales/{{lng}}/{{ns}}.yml')
2017-08-03 03:47:11 +00:00
}
})
2017-05-04 02:10:12 +00:00
2017-08-03 03:47:11 +00:00
// ----------------------------------------
// Start Queues
// ----------------------------------------
2017-08-03 03:47:11 +00:00
const Bull = require('bull')
const autoload = require('auto-load')
2017-02-09 01:52:37 +00:00
let queues = autoload(path.join(WIKI.SERVERPATH, 'queues'))
2017-02-09 01:52:37 +00:00
2017-07-29 21:33:08 +00:00
for (let queueName in queues) {
2017-08-03 03:47:11 +00:00
new Bull(queueName, {
prefix: `q-${WIKI.config.ha.nodeuid}`,
redis: WIKI.config.redis
2017-08-03 03:47:11 +00:00
}).process(queues[queueName])
2017-07-29 21:33:08 +00:00
}
2017-08-03 03:47:11 +00:00
// ----------------------------------------
// Shutdown gracefully
// ----------------------------------------
2017-08-03 03:47:11 +00:00
process.on('disconnect', () => {
process.exit()
})
2017-02-09 01:52:37 +00:00
})