Olivier Nguyen
Olivier Nguyen

Reputation: 151

QueueEvents don't trigger with BullMQ using Heroku Redis

I'm trying to implement a queue in NodeJS using BullMQ but i have some issues in production when trying to use a remote Redis (Heroku Redis or Redis Cloud).

In local, everything work well but when i try to use a REDIS_URL, a job is created but events doesn't work.

Here is the code:

// test_job.js
import { Queue, Worker, QueueEvents } from "bullmq";
import IORedis from "ioredis";

import Dotenv from "dotenv";
Dotenv.config();

// Good
const connection = new IORedis(process.env.REDIS_URL || 6379);

// Good
const queue = new Queue("Paint", { connection });

// Good
const worker = new Worker(
  "Paint",
  async job => {
    if (job.name === "cars") {
      console.log(job.data.color);
    }
  },
  { connection }
);

/**
 * BUG HERE: Events work in local but not when using a remote Redis (REDIS_URL)
 */
const queueEvents = new QueueEvents("Paint");
queueEvents.on("completed", jobId => {
  console.log("done painting");
});

queue.add("cars", { color: "blue" });

Upvotes: 1

Views: 2112

Answers (1)

Olivier Nguyen
Olivier Nguyen

Reputation: 151

const queueEvents = new QueueEvents("Paint", { connection: connection.duplicate() });

https://github.com/taskforcesh/bullmq/issues/173

Upvotes: 5

Related Questions