OptimalBits / bull

Premium Queue package for handling distributed jobs and messages in NodeJS.
Other
15.58k stars 1.43k forks source link

Task queuing works well locally but not in production #2728

Closed diegobejardelaguila closed 7 months ago

diegobejardelaguila commented 7 months ago

Description

It's happening to me that my redis configuration with bull works great locally but when I push it to production it doesn't work, I was wondering if there is an additional configuration when using bull + redis in production? I did not find any special configuration information in production, I am using a vercel server and my redis instance with redis.com.

Minimal, Working Test code to reproduce the issue.

const Queue = require("bull");
const { User } = require("../db");
const { Op } = require("sequelize");
const {
  emailNotificationProjectForProfessional,
} = require("../utils/emailNotificationProjectForProfessional");
const { emailRegisterProject } = require("../utils/emailRegisterProject");
const { sendProjectEmail } = require("../utils/emailProject");
const redisConfig = {
  redis: {
    host,
    port,
    password,
  },
};

const myQueue = new Queue("myQueue", redisConfig);

// Process jobs from the queue
myQueue.process(async (job) => {
  console.log("Processing job:", job.data);
  const {
    projectId,
    projectTitle,
    projectCompany,
    emailUserCreated,
    userNameCreated,
    project,
    userUid,
    emails,
  } = job.data;

  const usersEmail = await User.findAll({
    attributes: ["email"],
    where: {
      emailNotifications: true,
      email: {
        [Op.not]: emailUserCreated,
      },
    },
  });

  const userEmails = usersEmail.map((user) => user.email);

  // await sendProjectEmail(project);
  // await emailRegisterProject(userNameCreated, projectTitle, emailUserCreated);
  // Send email to each recipient
  await emailNotificationProjectForProfessional(
    projectId,
    projectTitle,
    projectCompany,
    userEmails
  );
  return Promise.resolve();
});

// Event listener for completed jobs
myQueue.on("completed", (job, result) => {
  console.log(`Job ID ${job.id} completed with result:`, result);
});

// Event listener for failed jobs
myQueue.on("failed", (job, err) => {
  console.error(`Job ID ${job.id} failed with error:`, err);
});

module.exports = { myQueue };

Bull version

4.12.2

manast commented 7 months ago

When you say "it is not working" what do you mean by that? what is not working specifically?

manast commented 7 months ago

btw, if you are using Bull in a new project I highly recommend you to use BullMQ, not only has the latest features but it is where all the efforts are being put these days...

manast commented 7 months ago

Closing due to lack of response.