我正在尝试使用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" });
1条答案
按热度按时间ggazkfy81#
https://github.com/taskforcesh/bullmq/issues/173