felixmosh / bull-board

🎯 Queue background jobs inspector
MIT License
2.14k stars 342 forks source link

[Nestjs][ExpressAdapter][Bull] HttpAdapterHost isn't available in the BullBoardRootModule context as per #590 #690

Closed russosalv closed 1 week ago

russosalv commented 4 months ago

i have same error as per #590

Nest can't resolve dependencies of the BullBoardRootModule (?, bull_board_adapter, bull_board_options). Please make sure that the argument HttpAdapterHost at index [0] is available in the BullBoardRootModule context.

but i have this main.ts

import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import * as appInsights from 'applicationinsights';
import { AppModule } from './app.module';
import { ApplicationInsightInterceptor } from './applicationInsight/applicationInsight.interceptor';
import { ApplicationInsightUtils } from './applicationInsight/applicationInsight.utils';
import { ApplicationInsightLogger } from './applicationInsight/applicationInsightLogger.utils';
import { AuxiliaryJobService } from './modules/auxiliary-job/auxiliary-job-service';
import { GetterJobService } from './modules/getter-job/getter-job.service';
import { SapSyncProcessConfigUtils } from './utils/sapSyncProcessConfig.utils';
import {
    AllExceptionFilter,
    SapRfcNoDataExtractedExceptionFilter,
    TooMuchRunNowJobFilter
} from "./filter/allException.filter";

async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    console.log('DATABASE_URL', process.env.DATABASE_URL);
    console.log('REDIS_HOST', process.env.REDIS_HOST);
    console.log('REDIS_PORT', Number(process.env.REDIS_PORT));

    const applicationInsight = await app.resolve(ApplicationInsightUtils);
    app.useGlobalInterceptors(new ApplicationInsightInterceptor(applicationInsight));

    applicationInsight.defaultClient?.trackEvent({
        name: 'SapSyncV2 Started',
        properties: {
            startTimeUtc: new Date(),
        },
    } as appInsights.Contracts.EventTelemetry);

    const logger = await app.resolve(ApplicationInsightLogger);
    app.useLogger(logger);

    app.useGlobalFilters(new TooMuchRunNowJobFilter(applicationInsight));
    app.useGlobalFilters(new SapRfcNoDataExtractedExceptionFilter(applicationInsight));

    const swaggerConfig = new DocumentBuilder()
        .setTitle('syncV2')
        .setDescription('syncV2')
        .setVersion('2.0')
        .addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' })
        .build();

    const document = SwaggerModule.createDocument(app, swaggerConfig, {
        // extraModels: [...PrismaModel.extraModels],
    });
    SwaggerModule.setup('api', app, document);

    const sapSyncProcessConfigUtils = await app.resolve(SapSyncProcessConfigUtils);
    const sapSyncProcessConfigs = await sapSyncProcessConfigUtils.getSapSyncProcessConfigsAll();
    const isFirstSyncAtAll = await sapSyncProcessConfigUtils.isFirstSyncAtAll();

    const getterJobService = await app.resolve(GetterJobService);
    const auxiliaryJobService = await app.resolve(AuxiliaryJobService);

    //** START BEFORE THE REGISTRATION OF QUEUES THEN DISCHARGE DATA */
    // if (isFirstSyncAtAll) {
    //  await getterJobService.startFirstSync();
    // }
    // await auxiliaryJobService.rescueGetter();
    // await auxiliaryJobService.rescueSetter();
    // await auxiliaryJobService.registerDefault();
    // getterJobService.registerScheduled(sapSyncProcessConfigs);

    app.enableCors({
        origin: '*',
    });

    await app.listen(3000).then(async () => {

        //TODO: REMOVE THIS
        return;

        if (isFirstSyncAtAll) {
            await getterJobService.startFirstSync();
        }
        await auxiliaryJobService.rescueGetter();
        await auxiliaryJobService.rescueSetter();

        await auxiliaryJobService.registerDefault();
        getterJobService.registerScheduled(sapSyncProcessConfigs);
    });
}
bootstrap();
DennisSnijder commented 4 months ago

@russosalv thanks for reporting this! Where are you registering the BullBoardModule in this example?

Can you give me the following list with the versions you're using?

Cheers!

russosalv commented 4 months ago

Hi @DennisSnijder

i register BullBoardModule in the app.module.ts

import {SapRfcModule} from "./modules/saprfc/saprfc.module";
import {BullBoardModule} from "@bull-board/nestjs";
import {ExpressAdapter} from "@bull-board/express";

@Module({
    imports: [
        ConfigModule.forRoot(),
        BullModule.forRoot({
            redis: {
                host: process.env.REDIS_HOST ?? 'localhost',
                port: process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379,
            },
        }),
        ScheduleModule.forRoot(),
        EventEmitterModule.forRoot(),
        AuthModule,
        DeveloperModule,
        GetterJobModule,
        SetterJobModule,
        AuxiliaryJobModule,
        WebsocketClientModule,
        SapRfcModule,
        DbConfigModule,
        BullBoardModule.forRoot({
            route: '/queues',
            adapter: ExpressAdapter
        }),
    ],
    controllers: [],
    providers: [
        {
            provide: APP_INTERCEPTOR,
            useClass: ApplicationInsightInterceptor,
        },
        ApplicationInsightLogger,
        ApplicationInsightUtils,
        PrismaService,
        RedisService,
        SapSyncProcessConfigUtils,
        ConfigService,
    ],
})
export class AppModule {}

versions are:

    "dependencies": {
        "@bull-board/api": "^5.14.1",
        "@bull-board/express": "^5.14.1",
        "@bull-board/nestjs": "^5.14.1",
        "@nestjs/bull": "^10.0.1",
        "@nestjs/common": "^10.2.7",
        "@nestjs/config": "^3.1.1",
        "@nestjs/core": "^10.2.7",
        "@nestjs/event-emitter": "^2.0.2",
        "@nestjs/platform-express": "^10.2.7",
        "@nestjs/schedule": "^3.0.4",
        "@nestjs/swagger": "^7.1.13",
        "applicationinsights": "^2.8.0",
        "axios": "^1.5.1",
        "bull": "^4.7.0",
        "cronstrue": "^1.125.0",
        "decimal.js": "^10.4.3",
        "easy-soap-request": "^4.6.0",
        "fast-xml-parser": "^4.0.2",
        "keycloak-connect": "^15.0.2",
        "lodash": "^4.17.21",
        "moment": "^2.29.1",
        "moment-timezone": "^0.5.34",
        "nest-keycloak-connect": "^1.7.6",
        "nestjs-sap-rfc": "^3.0.33",
        "prisma-query-log": "^3.2.0",
        "redis": "^4.0.3",
        "reflect-metadata": "^0.1.13",
        "rimraf": "^3.0.2",
        "rxjs": "^7.2.0",
        "socket.io-client": "^4.4.1",
        "string-hash": "^1.1.3",
        "swagger-ui-express": "^5.0.0",
        "uuid": "^8.3.2"
    }
russosalv commented 3 months ago

Any Update for that? still have issue anso using version 5.15.1

felixmosh commented 3 months ago

Did you checked examples folder, it works there...

Unfortunately, I'm not so familiar with Nest.js, so I can't help you

Enflow-io commented 3 months ago

+1

russosalv commented 3 months ago

i think that the issue is related to yarn version and node version i'm using node 16 and yarn 1.x

felixmosh commented 3 months ago

@russosalv can you confirm that #704 solves this issue?

stale[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.