Bull would not run without redis on localhost:6379, even when I run redis on a different port

Viewed 546

I am using Bull to process send out mails when hasura sees an update on the table and triggers the payload to the email microservice.

The issue is, that although the hasura successfully sends the payload, the controller is unable to queue the information if redis is not running on localhost:6379 even when I am running redis on 6380 and specifying it in

BullModule.registerQueue({ name: MAIL_QUEUE, redis: {host: 'localhost', port: 6380 })

On top of that, if there is a redis instance running on 6379, then Bull completely ignores the parameters I use inside the registerQueue, and works smoothly using redis 0n 6379, somehow.

For reproduction :

mail.module.ts

@Module({
  imports: [
    BullModule.registerQueue({ name: MAIL_QUEUE, redis: REDIS_QUEUE_URL }),
    UserModule
  ],
  controllers: [MailController],
  providers: [MailService, MailProcessor],
})
export class MailModule {}

mail.processor.ts

@Processor(MAIL_QUEUE)
export class MailProcessor {
  constructor(
    private readonly mailService: MailService,
    private readonly userService: UserService,
  ) {}
@Process('mail_principal_on_school_create')
  async mailPrincipalOnSchoolCreate(job: Job) {
    const schoolname = job.data.schoolname;
    const email = job.data.email;
    const firstname = job.data.firstname;
    const lastname = job.data.lastname;

    await this.mailService.sendMail(
      {
        name: `${firstname} ${lastname}`,
        schoolname: schoolname,
        email: email,
      },
      POSTMARK_MAIL_PRINCIPAL_ON_SCHOOLCREATE_TEMPLATE_ID,
    );
  }
}

user.service.ts

@Injectable()
export class UserService {
  constructor(
    @InjectQueue(MAIL_QUEUE) private mailQueue: Queue,
  ){}
async mailPrincipalOnSchoolCreate(data) {
    const school_name = data.event.data.new.name;
    const email = data.event.data.new.principal_email;
    const firstname = data.event.data.new.principal_name;
    const lastname = data.event.data.new.principal_surname;

    this.mailQueue.add('mail_principal_on_school_create', {
      email: email,
      firstname: firstname,
      lastname: lastname,
      schoolname: school_name,
    });
  }
}

So the trigger from hasura reaches user.service.ts but never gets added to the queue unless there is a redis instance running on 6379.

And btw, here is the error :

(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:126435) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

HELP!!

0 Answers
Related