OptimalBits / bull

Premium Queue package for handling distributed jobs and messages in NodeJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bull fails in add queue in Docker

jdgabriel opened this issue · comments

Description

Bull seamlessly connects to Redis whether it's through IORedis or not. Always connect.

I can add key and value in redis normally.

The problem is when I use a connection that comes from Redis in a Docker container. Everything connects, but doesn't add to the queue. It only works if my app is on localhost and redis is in container. But if both are in container, it connects but doesn't work for Bull's queues.

Minimal, Working Test code to reproduce the issue.

(An easy to reproduce test case will dramatically decrease the resolution time.)

version: "3"

services:
  app:
    build: .
    container_name: app
    ports:
      - "3090:3090"
    restart: always
    volumes:
      - .:/app
    networks:
      - app-network

  redis:
    image: bitnami/redis:7.0-debian-11
    container_name: redis
    environment:
      - REDIS_PASSWORD=alowdonamaria
      - REDIS_PORT_NUMBER=6380
    ports:
      - "6380:6380"
    restart: always
    volumes:
      - redis-data:/data
    networks:
      - app-network

volumes:
  redis-data:

networks:
  app-network:

When importing the configuration:

import jobs from './jobs';

const queues = Object.values(jobs).map((job) => ({
  bull: new Queue(job.key, {
    connection: {
      redis: {
        host: process.env.REDIS_HOST,
        port: process.env.REDIS_PORT,
        password: process.env.REDIS_PASS,
      },
    },
  }),
  name: job.key,
  handler: job.handler,
  options: {
    delay: 5000,
    attempts: 3,
    removeOnComplete: process.env.NODE_ENV !== "dev",
    ...job.options,
  },
}));

module.exports = {
  queues,
  add({ name, data }) {
    const queue = this.queues.find((queue) => queue.name === name);
    if (!queue) return;
    console.log({ name, queue: queue.bull });
    return queue.bull.add(name, data, queue.options);
  },
  process() {
    return this.queues.forEach((queue) => {
      queue.bull.process(queue.name, 1, queue.handler);
      queue.bull.on("failed", (job, err) => {
        console.log("Job failed", queue.name, job.data);
        console.log(err);
      });
    });
  },
};

Result in my terminal
image

Just add the queue, to get a connection timeout
PS: I have another app with EXACTLY THIS CONFIGURATION, and it works.

I can't get it to work, I'm going crazy.

Bull version

4.10.2
But I already did the test with the version 4.11.3