'Await database before register queue using nestjs
I need to get database value before register using nestjs/bull package, how can I achieve this?
@Module({
imports: [
/* Db Import */
TypeOrmModule.forFeature([TransactionRepository]),
BullModule.registerQueueAsync(
{
name: `${GlobalService.namespace}:${GlobalService.QUEUE_DELIVERY}`,
useFactory: async () => {
const data = await initQueue(getManager()) // get data from typeorm getManager not working
return {
limiter: {
max: Number(data.CALLBACK_TPS),
duration: 1000,
}
}
},
},
),
],
controllers: [ApiController],
providers: [ApiService, ResponseApiUtil],
})
This is error code
[Nest] 1465026 - 03/20/2022, 3:10:23 AM ERROR [ExceptionHandler] Connection is not established with mysql database
TypeORMError: Connection is not established with mysql database
Solution 1:[1]
You can inject the connection to the factory using inject: [getConnectionToken()] like
@Module({
imports: [
/* Db Import */
TypeOrmModule.forFeature([TransactionRepository]),
BullModule.registerQueueAsync(
{
name: `${GlobalService.namespace}:${GlobalService.QUEUE_DELIVERY}`,
inject: [getConnectionToken()],
useFactory: async (connection: Connection) => {
const data = await initQueue(connection.getManager())
return {
limiter: {
max: Number(data.CALLBACK_TPS),
duration: 1000,
}
}
},
},
),
],
controllers: [ApiController],
providers: [ApiService, ResponseApiUtil],
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jay McDoniel |
