DennisSnijder / nestjs-bull-board

NestJS module for bull-board
https://www.npmjs.com/package/nestjs-bull-board
1 stars 0 forks source link
bull bull-board bullmq nestjs nestjs-module

This package has been migrated

This package has been migrated to the official bull-board repository and will be maintained from there.

Please use the official @bull-board/nestjs package for future support and maintenance.

NestJS bull-board module

A simple NestJS module for using bull-board with NestJS.

NPM

Installation

Install both @bull-board/api and this module.

$ npm install --save nestjs-bull-board @bull-board/api

Install the Express or Fastify adapter depending on what you use in NestJS (default is Express)

$ npm install --save @bull-board/express
//or 
$ npm install --save @bull-board/fastify

Register the root module

Once the installation is completed, we can import the BullBoardModule into your rootmodule e.g. AppModule.

import { Module } from '@nestjs/common';
import { BullBoardModule } from "nestjs-bull-board";
import { ExpressAdapter } from "@bull-board/express";

@Module({
  imports: [
    BullModule.forRoot({
      // your bull module config here.
    }),

    BullBoardModule.forRoot({
      route: '/queues',
      adapter: ExpressAdapter // Or FastifyAdapter from `@bull-board/fastify`
    }),
  ],
})
export class AppModule {
}

The forRoot() method registers the bull-board instance and allows you to pass several options to both the instance and module. The following options are available.

Register your queues

To register a new queue, you need to register BullBoardModule.forFeature in the same module as where your queues are registered.

import { Module } from '@nestjs/common';
import { BullBoardModule } from "nestjs-bull-board";
import { BullModule } from "@nestjs/bullmq";

@Module({
  imports: [
    BullModule.registerQueue(
      {
        name: 'my_awesome_queue'
      }
    ),

    BullBoardModule.forFeature({
      name: 'my_awesome_queue',
      adapter: BullMQAdapter, //or use BullAdapter if you're using bull instead of bullMQ
    }),
  ],
})
export class FeatureModule {}

The forFeature method registers the given queues to the bull-board instance. The following options are available.

Using the bull-board instance in your controllers and/or services.

The created bull-board instance is available via the @InjectBullBoard() decorator. For example in a controller:

import { Controller, Get } from "@nestjs/common";
import { BullBoardInstance, InjectBullBoard } from "nestjs-bull-board";

@Controller('my-feature')
export class FeatureController {

  constructor(
    @InjectBullBoard() private readonly boardInstance: BullBoardInstance
  ) {
  }

  //controller methods
}