Bull: Define Queue in a different module

Created on 12 Oct 2017  路  3Comments  路  Source: OptimalBits/bull

I want to define my Queue and it's process function in a different module. In another module I import the exported queue object and I call myQueue.add('example-data-params')

In redis I can see it actually adds these jobs, but all of them fail with the reason

Missing process handler for job type example-data-params

Isn't that possible?

File A:

import { myQueue } from '../jobs/xy'
myQueue.add('example-data-params')

File B:

export const myQueue = new Queue('refresh users')
myQueue.process(400, processExample)

function processExample(job) {
  console.log('ok')
  return
}

Edit: Before I tried instead of export + import to create a new Queue with the same name and use that new object to add jobs on. The outcome was exactly the same -> Jobs were added tor edis but all showed up as failed because of a "missing process function"

Edit 2: I just saw in the documentation that you've added a new parameter for the queue.add method. The first parameter is the name. The typings at definetelyTyped seem to be outdated as they don't show the name parameter there. I've fixed the typing to add(name?: string, data?: any, opts?: JobOptions): Promise<Job>;

Adding jobs following that pattern does still lead to the same error though.

Most helpful comment

As you can see in the signature, the first parameter is the name of the job. You need a handler that is defined for that name like this:

queue.process('example-data-params', (job) => ... );

All 3 comments

As you can see in the signature, the first parameter is the name of the job. You need a handler that is defined for that name like this:

queue.process('example-data-params', (job) => ... );

I see, the typings for that need to be updated as well for @types/bull then.

Assuming I created named jobs and define the processor like this:
myQueue.process(400, processExample) it wouldn't process the named jobs at all then?

no, you need to define a processor for every named job as explained above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chocof picture chocof  路  3Comments

btd picture btd  路  3Comments

sibelius picture sibelius  路  3Comments

rodrigoords picture rodrigoords  路  4Comments

pigaov10 picture pigaov10  路  3Comments