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.

35 lines
906 B

  1. const Bull = require('bull')
  2. const Promise = require('bluebird')
  3. /* global WIKI */
  4. module.exports = {
  5. init() {
  6. WIKI.data.queues.forEach(queueName => {
  7. this[queueName] = new Bull(queueName, {
  8. prefix: `q-${WIKI.config.ha.nodeuid}`,
  9. redis: WIKI.config.redis
  10. })
  11. })
  12. return this
  13. },
  14. clean() {
  15. return Promise.each(WIKI.data.queues, queueName => {
  16. return new Promise((resolve, reject) => {
  17. let keyStream = WIKI.redis.scanStream({
  18. match: `q-${WIKI.config.ha.nodeuid}:${queueName}:*`
  19. })
  20. keyStream.on('data', resultKeys => {
  21. if (resultKeys.length > 0) {
  22. WIKI.redis.del(resultKeys)
  23. }
  24. })
  25. keyStream.on('end', resolve)
  26. })
  27. }).then(() => {
  28. WIKI.logger.info('Purging old queue jobs: [ OK ]')
  29. }).return(true).catch(err => {
  30. WIKI.logger.error(err)
  31. })
  32. }
  33. }