mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
906 B
36 lines
906 B
7 years ago
|
const Bull = require('bull')
|
||
|
const Promise = require('bluebird')
|
||
|
|
||
7 years ago
|
/* global wiki */
|
||
|
|
||
7 years ago
|
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(() => {
|
||
7 years ago
|
wiki.logger.info('Purging old queue jobs: [ OK ]')
|
||
7 years ago
|
}).return(true).catch(err => {
|
||
7 years ago
|
wiki.logger.error(err)
|
||
|
})
|
||
|
}
|
||
|
}
|