wikijs-fork/server/core/queue.js

36 lines
906 B
JavaScript
Raw Normal View History

2017-08-03 03:47:11 +00:00
const Bull = require('bull')
const Promise = require('bluebird')
/* global WIKI */
2017-08-03 03:47:11 +00:00
module.exports = {
init() {
WIKI.data.queues.forEach(queueName => {
2017-08-03 03:47:11 +00:00
this[queueName] = new Bull(queueName, {
prefix: `q-${WIKI.config.ha.nodeuid}`,
redis: WIKI.config.redis
2017-08-03 03:47:11 +00:00
})
})
return this
},
clean() {
return Promise.each(WIKI.data.queues, queueName => {
2017-08-03 03:47:11 +00:00
return new Promise((resolve, reject) => {
let keyStream = WIKI.redis.scanStream({
match: `q-${WIKI.config.ha.nodeuid}:${queueName}:*`
2017-08-03 03:47:11 +00:00
})
keyStream.on('data', resultKeys => {
if (resultKeys.length > 0) {
WIKI.redis.del(resultKeys)
2017-08-03 03:47:11 +00:00
}
})
keyStream.on('end', resolve)
})
}).then(() => {
WIKI.logger.info('Purging old queue jobs: [ OK ]')
2017-10-08 02:44:35 +00:00
}).return(true).catch(err => {
WIKI.logger.error(err)
2017-08-03 03:47:11 +00:00
})
}
}