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 => {
this[queueName] = new Bull(queueName, {
prefix: `q-${wiki.config.ha.nodeuid}`,
redis: wiki.config.redis
})
})
return this
},
clean() {
return Promise.each(wiki.data.queues, queueName => {
return new Promise((resolve, reject) => {
let keyStream = wiki.redis.scanStream({
match: `q-${wiki.config.ha.nodeuid}:${queueName}:*`
})
keyStream.on('data', resultKeys => {
if (resultKeys.length > 0) {
wiki.redis.del(resultKeys)
}
})
keyStream.on('end', resolve)
})
}).then(() => {
2017-12-24 05:34:47 +00:00
wiki.logger.info('Purging old queue jobs: [ OK ]')
2017-10-08 02:44:35 +00:00
}).return(true).catch(err => {
2017-08-03 03:47:11 +00:00
wiki.logger.error(err)
})
}
}