RomainLanz / adonis-bull-queue

Queue system based on BullMQ for AdonisJS
MIT License
147 stars 26 forks source link

Cannot read properties of undefined (reading 'dispatch') on command #59

Closed kadirgun closed 10 hours ago

kadirgun commented 10 hours ago
import { BaseCommand } from '@adonisjs/core/ace'
import type { CommandOptions } from '@adonisjs/core/types/ace'
import queue from '@rlanz/bull-queue/services/main'
import TestJob from '../app/jobs/test_job.js'

export default class Test extends BaseCommand {
  static commandName = 'queue:test'
  static description = ''

  static options: CommandOptions = {}

  async run() {
    queue.dispatch(TestJob, {})
  }
}
node ace queue:test

   TypeError: Cannot read properties of undefined (reading 'dispatch')

   at Test.run commands/test.ts:9
kadirgun commented 10 hours ago

It's my fault. I should have specified whether the app should be booted or not with the startApp option when running console commands.

import { BaseCommand } from '@adonisjs/core/ace'
import type { CommandOptions } from '@adonisjs/core/types/ace'
import queue from '@rlanz/bull-queue/services/main'
import TestJob from '../app/jobs/test_job.js'

export default class Test extends BaseCommand {
  static commandName = 'queue:test'
  static description = ''

  static options: CommandOptions = {
    startApp: true
  }

  async run() {
    queue.dispatch(TestJob, {})
  }
}