#Is this a good practice for module ?

6 messages · Page 1 of 1 (latest)

viral summit
#

Hello everyone, I'm new to this Discord.

I have a quick question about modules. Is this a good practice to start my consumer here ?

@Module({
  imports: [ContactModule],
  controllers: [SchedulerController],
  providers: [
    SchedulerService,
    {
      provide: 'SqsSchedulerConsumer',
      useFactory: (schedulerService: SchedulerService) => {
        const consumer = new SqsSchedulerConsumer(schedulerService);
        consumer.start(); // Here <<<<<<
        return consumer;
      },
    },
  ],
  exports: [],
})
export class SchedulerModule {}

I tried using OnApplicationBootstrap implementation in my SqsSchedulerConsumer class, but it never gets triggered at startup.
What is the best way to inject and start my SQS consumer ?

Thank you for your help !

arctic sigil
#

Worst case, it's internals can give you an idea what to do.

viral summit
#

I'm going to see how this works in depth. Thank you !

tough fern
#

Short answer: no, it is not a good practise to connect to infrastructure directly in constructors and factory functions

#

OnApplicationBootstrap should be the place to do it. If it doesn't work for you, maybe you misconfigured something somewhere.