text: import Bee from 'bee-queue'
  import CancellationMail from '../app/jobs/CancellationMail'
  import redisConfig from '../config/redis'
  
  const jobs = [CancellationMail]
  
  class Queue {
    constructor () {
      // queus para carregar os jobs que sao igual os models porem sao chamods de jobs
      this.queues = {}
      this.init()
    }
  
    init () {
      jobs.forEach(({ key, handle }) => {
        this.queues[key] = {
          bee: new Bee(key, {
            redis: redisConfig
          }),
          handle
        }
      })
    }
  
    add (queue, job) {
      return this.queues[queue].bee.createJob(job).save()
    }
  
    processQueue () {
      jobs.forEach(job => {
        const { bee, handle } = this.queues[job.key]
  
        bee.on('failed', this.handleFailure).process(handle)
      })
    }
  
    handleFailure (job, err) {
      console.log(`Queue ${job.queue.name}:FAILED`, err)
    }
  }
  export default new Queue()
  