fix: localization master callback + various fixes

This commit is contained in:
Nicolas Giard
2018-11-18 16:38:00 -05:00
parent 3abc254685
commit 27adad8dad
10 changed files with 69 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
const _ = require('lodash')
const EventEmitter = require('events')
/* global WIKI */
@@ -23,6 +24,8 @@ module.exports = {
await WIKI.models.onReady
await WIKI.configSvc.loadFromDb()
await WIKI.queue.clean()
WIKI.events = new EventEmitter()
WIKI.redisSub = require('./redis').subscribe()
} catch (err) {
WIKI.logger.error(err)
process.exit(1)

View File

@@ -33,6 +33,15 @@ module.exports = {
// Load current language + namespaces
this.refreshNamespaces(true)
// Listen for localization events
WIKI.events.on('localization', (action) => {
switch (action) {
case 'reload':
this.refreshNamespaces()
break
}
})
return this
},
attachMiddleware (app) {

View File

@@ -36,6 +36,11 @@ module.exports = {
}
})
},
async quit() {
for (const queueName in this.job) {
await this.job[queueName].close()
}
},
async clean() {
return Promise.each(_.keys(WIKI.data.jobs), queueName => {
return new Promise((resolve, reject) => {

View File

@@ -19,5 +19,19 @@ module.exports = {
WIKI.logger.error('Invalid Redis configuration!')
process.exit(1)
}
},
subscribe() {
let red = this.init()
red.on('message', (channel, msg) => {
WIKI.events.emit(channel, msg)
})
red.subscribe('localization', (err, count) => {
if (err) {
WIKI.logger.error(err)
process.exit(1)
}
WIKI.logger.info('Redis Subscriber connection: [ OK ]')
})
return red
}
}