acidiney / bull-queue

AdonisJS package to work with bull queues
MIT License
3 stars 2 forks source link

Confusing Usage #1

Closed sooluh closed 5 months ago

sooluh commented 6 months ago

I'm trying it out, but it's not working. Am I missing any steps?

I want to run the job when opening one of the methods in the controller that has been registered to the route. I call it with the following code:

await bull.dispatch(ExampleHandlerJob.name, { app, payload } as ExampleHandlerPayload)

but it's not working at all. The process inside the handle() method doesn't work, even in the failed() method.

acidiney commented 6 months ago

And have you started the worker process? node ace queue:listen?

sooluh commented 6 months ago

Actually, I haven't executed it yet, but I want when the server is running to simultaneously run BullMQ as well. I create start/bull.ts and add it to the preloads in adonisrc.ts, and the code is as follows,

import net from 'net'
import app from '@adonisjs/core/services/app'
import queue from '@acidiney/bull-queue/services/main'

const PORT = 9999
const server = net.createServer()

server.once('error', async (error: any) => {
  if (error.code === 'EADDRINUSE') {
    queue.list().forEach(async (queue) => {
      await queue.close()
    })
  }
})

server.once('listening', async () => {
  server.close()
  // await queue.processBulk(Object.keys(queue.list()))

  if (app.inDev) {
    await queue.ui(PORT || 9999, Object.keys(queue.list()))
  }
})

server.listen(PORT)

Any idea? Perhaps my above code is not quite right.