2017-08-03 03:47:11 +00:00
|
|
|
const Bull = require('bull')
|
|
|
|
const Promise = require('bluebird')
|
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2018-02-04 05:53:13 +00:00
|
|
|
|
2017-08-03 03:47:11 +00:00
|
|
|
module.exports = {
|
|
|
|
init() {
|
2018-03-05 20:49:36 +00:00
|
|
|
WIKI.data.queues.forEach(queueName => {
|
2017-08-03 03:47:11 +00:00
|
|
|
this[queueName] = new Bull(queueName, {
|
2018-03-05 20:49:36 +00:00
|
|
|
prefix: `q-${WIKI.config.ha.nodeuid}`,
|
|
|
|
redis: WIKI.config.redis
|
2017-08-03 03:47:11 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
clean() {
|
2018-03-05 20:49:36 +00:00
|
|
|
return Promise.each(WIKI.data.queues, queueName => {
|
2017-08-03 03:47:11 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-03-05 20:49:36 +00:00
|
|
|
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) {
|
2018-03-05 20:49:36 +00:00
|
|
|
WIKI.redis.del(resultKeys)
|
2017-08-03 03:47:11 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
keyStream.on('end', resolve)
|
|
|
|
})
|
|
|
|
}).then(() => {
|
2018-03-05 20:49:36 +00:00
|
|
|
WIKI.logger.info('Purging old queue jobs: [ OK ]')
|
2017-10-08 02:44:35 +00:00
|
|
|
}).return(true).catch(err => {
|
2018-03-05 20:49:36 +00:00
|
|
|
WIKI.logger.error(err)
|
2017-08-03 03:47:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|