Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with registerQueueAsync in NestJs #649

Open
GianlucaCesari opened this issue Nov 21, 2023 · 2 comments
Open

Error with registerQueueAsync in NestJs #649

GianlucaCesari opened this issue Nov 21, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@GianlucaCesari
Copy link

GianlucaCesari commented Nov 21, 2023

Hello, I'm trying to use BullBoardModule with a very specific case.

Basically,
instead of registering a queue with the default BullModule.registerQueue I'm doing something like this

BullModule.registerQueueAsync({
      imports: [AppModule],
      useFactory: async (appService: AppService) => {
        // Logic to determine the number of logged-in credentials
        const loggedInCount = await appService.onModuleInit();

        // Use loggedInCount to determine concurrency, for example:
        const concurrency = Math.max(1, loggedInCount); // Ensure a minimum concurrency of 1

        return {
          name: 'main_queue',
          processors: [
            {
              concurrency: concurrency,
              path: join(__dirname, 'processors/main_queue.processor.js'),
            },
          ],
        };
      },
      inject: [AppService],
    }),
    BullBoardModule.forFeature({
      name: 'main_queue',
      adapter: BullMQAdapter,
    }),

The problem I think is that BullBoardModule tries to start up before the queue is actually registered throwing this error

            throw new unknown_element_exception_1.UnknownElementException(this.getInstanceNameByToken(token));
                  ^
Error: Nest could not find BullQueue_main_queue element (this provider does not exist in the current context)


Any suggestion on how to fix it? I don't see an async mode, is it not supported?

@felixmosh
Copy link
Owner

Hi, thank you for reporting this issue,
I'm not an expert with Nest.js... (maybe I should become one)
Bull-board, the core do supports async addition /removal of queues...

I'll happy to get any help here

@felixmosh felixmosh added bug Something isn't working help wanted Extra attention is needed labels Nov 21, 2023
@felixmosh
Copy link
Owner

Hi,
I'm not sure if this is possible, but, if you can inject the

@Inject(BULL_BOARD_INSTANCE) private readonly board: BullBoardInstance

you will be able to add queue dynamically, by calling this.board.add() as it done in here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants