nestjs / bull

Bull module for Nest framework (node.js) :cow:
https://nestjs.com
MIT License
597 stars 98 forks source link

Nestjs bull Consumer process() doesn't pick up job from queue to process #2165

Closed Geoelycom closed 1 month ago

Geoelycom commented 1 month ago

Is there an existing issue for this?

Current behavior

I have two Microservices Services A( Auth service is a GRPC service) and service B(email service which is an HTTP service)

Service A gets user data authenticates them and produces data to a queue using bull on nestjs Service B the email service is supposed to consume this data produced by service A to send emails to the users service A authenticated.

Service A produces these messages and I have used the bullboard to view these messages and see that they are in the queue.

But service B isn’t picking these jobs up to process them and send the emails to the recipients(users) But when I wrote a test script for service B to check if it could consume messages it worked fine and the emails were sent. The jobs are In the queue but service B isn’t picking them up. There are no error logs to show me what could be going wrong despite including detailed logs to catch anything that might be causing it not picking the jobs from the queue. the consumer code gets instantaited, as i included a log to actually ensure it does gets started and i get the logs as you can see below.

@Processor('easepay-email-queue')
export class EmailQueueConsumer {
  constructor(
    private readonly mailerService: MailerService,
    private readonly configService: ConfigService,
    @InjectPinoLogger(EmailQueueConsumer.name)
    private readonly logger: PinoLogger,
  ) {
    this.logger.info('EmailQueueConsumer instantaited');
  }

LOGS
{"level":30,"time":1721227301758,"pid":17472,"hostname":"Geo-MacBook-Pro.local","context":"EmailQueueConsumer","msg":"EmailQueueConsumer instantaited"}

But after this, nothing works. I have ensured that both services A and B use the same queue name. I have triple-checked to ensure this is the case. ensured both services shared the same Redis connection and checked with Redis Insight to ensure the jobs were being produced correctly. Both are the same but no matter how many data services A produces and sends to the queue currently at 65, service B isn’t consuming them. I logged the result of adding a job to the queue from service A and got the below output.

name: 'send-email',
    queue: Queue {
      name: 'easepay-email-queue',
      token: '66c59838-ebb3-49e0-a200-023e5b419067',
      keyPrefix: 'bull',
      clients: [Array],
      clientInitialized: true,
      _events: [Object: null prototype],
      _eventsCount: 2,
      _initializing: [Promise],
      handlers: {},
      processing: [],
      retrieving: 0,
      drained: true,
      settings: [Object],
      metrics: undefined,
      timers: [TimerManager],
      moveUnlockedJobsToWait: [Function: bound ],
      processJob: [Function: bound ],
      getJobFromId: [Function: bound ] AsyncFunction,
      keys: [Object],
      onApplicationShutdown: [Function (anonymous)]
    },
    data: {
      emailSubject: 'Account verification',
      recipient: 'ekenimohelyanpheta+1459356@gmail.com',
      emailTemplate: 'verify-email',
      data: [Object]
    },
    _progress: 0,
    delay: 0,
    timestamp: 1721240936373,
    stacktrace: [],
    returnvalue: null,
    attemptsMade: 0,
    toKey: [Function: wrapper],
    id: '25'
  }
}

the handlers and process are empty, they shouldn't be. I have searched existing issues and found the same issue from 2021 that wasn't solved here issue #1123 Before you refer me to the discord server, I have gone there and dropped this same message and there hasn't been any response for the past two days, and if anything is to go by, I couldn't find the old discord message of this same issue @Mellywins posted on the same issue.

The @process() method is supposed to pick up the job from the queue with the name send-email but it doesn't do that. it seems as if the @process() method does not work. and if it does not work, the handler method which does the consumer logic will not work. which is the issue @Mellywins faced in 2021. I would really appreciate it if you could take a look at this. maybe I am doing something wrong, i would also like to know, i believe I have followed all the design principles and nothing is missing but I am open to suggestions on how I can make this work if it's my code that is wrong. I look forward to hearing from you guys.

Regards Geo

Minimum reproduction code

https://gist.github.com/Geoelycom/ffe5524c034e00aa45c18dcb647b57d2

Steps to reproduce

No response

Expected behavior

The @process() is supposed to pick up the jobs from the queue and process them with the handler method. this doesn't happen. it seems like the whole @process() method does not work.

Package version

10.1.1

Bull version

No response

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 1 month ago

Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the #⁠ 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.