使用heroku redis的bullmq不会触发queueevents

v64noz0r  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(399)

我正在尝试使用bullmq在nodejs中实现一个队列,但是在尝试使用远程redis(heroku redis或redis cloud)时,我在生产中遇到了一些问题。
在本地,一切都很好,但当我尝试使用redis\uurl时,会创建一个作业,但事件不起作用。
代码如下:

// 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" });
ggazkfy8

ggazkfy81#

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

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

相关问题