feat: locales remote fetch+ deps update + fixes
This commit is contained in:
@@ -10,7 +10,7 @@ module.exports = {
|
||||
init() {
|
||||
if (cluster.isMaster) {
|
||||
WIKI.logger.info('=======================================')
|
||||
WIKI.logger.info('= WIKI.js =============================')
|
||||
WIKI.logger.info('= Wiki.js =============================')
|
||||
WIKI.logger.info('=======================================')
|
||||
|
||||
WIKI.redis = require('./redis').init()
|
||||
@@ -55,13 +55,7 @@ module.exports = {
|
||||
async postBootMaster() {
|
||||
await require('../master')()
|
||||
|
||||
_.times(this.numWorkers, () => {
|
||||
this.spawnWorker()
|
||||
})
|
||||
|
||||
WIKI.queue.uplClearTemp.add({}, {
|
||||
repeat: { cron: '*/15 * * * *' }
|
||||
})
|
||||
WIKI.queue.start()
|
||||
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
if (!global.DEV) {
|
||||
|
@@ -1,9 +1,7 @@
|
||||
const _ = require('lodash')
|
||||
const dotize = require('dotize')
|
||||
const i18nBackend = require('i18next-node-fs-backend')
|
||||
const i18nMW = require('i18next-express-middleware')
|
||||
const i18next = require('i18next')
|
||||
const path = require('path')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
/* global WIKI */
|
||||
@@ -14,17 +12,14 @@ module.exports = {
|
||||
init() {
|
||||
this.namespaces = WIKI.data.localeNamespaces
|
||||
this.engine = i18next
|
||||
this.engine.use(i18nBackend).init({
|
||||
this.engine.init({
|
||||
load: 'languageOnly',
|
||||
ns: this.namespaces,
|
||||
defaultNS: 'common',
|
||||
saveMissing: false,
|
||||
preload: [WIKI.config.site.lang],
|
||||
lng: WIKI.config.site.lang,
|
||||
fallbackLng: 'en',
|
||||
backend: {
|
||||
loadPath: path.join(WIKI.SERVERPATH, 'locales/{{lng}}/{{ns}}.yml')
|
||||
}
|
||||
fallbackLng: 'en'
|
||||
})
|
||||
return this
|
||||
},
|
||||
|
@@ -1,17 +1,16 @@
|
||||
const _ = require('lodash')
|
||||
const cluster = require('cluster')
|
||||
const winston = require('winston')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
loggers: {},
|
||||
init() {
|
||||
init(uid) {
|
||||
let logger = winston.createLogger({
|
||||
level: WIKI.config.logLevel,
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.label({ label: (cluster.isMaster) ? 'MASTER' : `WORKER-${cluster.worker.id}` }),
|
||||
winston.format.label({ label: uid }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`)
|
||||
)
|
||||
|
@@ -1,23 +1,40 @@
|
||||
const path = require('path')
|
||||
const Bull = require('bull')
|
||||
const Promise = require('bluebird')
|
||||
const _ = require('lodash')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
job: {},
|
||||
init() {
|
||||
WIKI.data.queues.forEach(queueName => {
|
||||
this[queueName] = new Bull(queueName, {
|
||||
prefix: `q-${WIKI.config.ha.nodeuid}`,
|
||||
_.forOwn(WIKI.data.jobs, (queueParams, queueName) => {
|
||||
this.job[queueName] = new Bull(queueName, {
|
||||
prefix: `q-${WIKI.config.ha.uid}`,
|
||||
redis: WIKI.config.redis
|
||||
})
|
||||
this.job[queueName].process(path.join(WIKI.SERVERPATH, `jobs/${_.kebabCase(queueName)}.js`))
|
||||
})
|
||||
return this
|
||||
},
|
||||
clean() {
|
||||
return Promise.each(WIKI.data.queues, queueName => {
|
||||
start() {
|
||||
_.forOwn(WIKI.data.jobs, (queueParams, queueName) => {
|
||||
if (queueParams.onInit) {
|
||||
this.job[queueName].add({}, {
|
||||
removeOnComplete: true
|
||||
})
|
||||
}
|
||||
this.job[queueName].add({}, {
|
||||
repeat: { cron: queueParams.cron },
|
||||
removeOnComplete: true
|
||||
})
|
||||
})
|
||||
},
|
||||
async clean() {
|
||||
return Promise.each(_.keys(WIKI.data.jobs), queueName => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let keyStream = WIKI.redis.scanStream({
|
||||
match: `q-${WIKI.config.ha.nodeuid}:${queueName}:*`
|
||||
match: `q-${WIKI.config.ha.uid}:${queueName}:*`
|
||||
})
|
||||
keyStream.on('data', resultKeys => {
|
||||
if (resultKeys.length > 0) {
|
||||
|
18
server/core/worker.js
Normal file
18
server/core/worker.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const path = require('path')
|
||||
|
||||
let WIKI = {
|
||||
IS_DEBUG: process.env.NODE_ENV === 'development',
|
||||
ROOTPATH: process.cwd(),
|
||||
SERVERPATH: path.join(process.cwd(), 'server'),
|
||||
Error: require('../helpers/error'),
|
||||
configSvc: require('./config')
|
||||
}
|
||||
global.WIKI = WIKI
|
||||
|
||||
WIKI.configSvc.init()
|
||||
|
||||
// ----------------------------------------
|
||||
// Init Logger
|
||||
// ----------------------------------------
|
||||
|
||||
WIKI.logger = require('./logger').init('JOB')
|
Reference in New Issue
Block a user