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.

37 lines
903 B

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