Socket
Socket
Sign inDemoInstall

@mobizerg/nest-bull

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mobizerg/nest-bull

A Bull integration module for nestjs framework


Version published
Maintainers
1
Created

Readme

Source

Nest Logo

A Bull redis queue integration module for Nest.js framework.

Installation

Yarn

yarn add @mobizerg/nest-bull bull ioredis
yarn add @types/bull --dev

NPM

npm install @mobizerg/nest-bull bull ioredis --save
npm install @types/bull --save-dev

Description

Redis Queue integration module for Nest.js based on the Bull package.

Usage

Import the BullModule in app.module.ts

import { Module } from '@nestjs/common';
import { BullModule } from '@mobizerg/nest-bull';
import { QueueJobProcessor } from './queue-job.processor';

@Module({
    imports: [
        BullModule.register(options),
    ],
    providers: [QueueJobProcessor],
})
export class AppModule {}

With Async

import { Module } from '@nestjs/common';
import { BullModule } from '@mobizerg/nest-bull';
import { QueueJobProcessor } from './queue-job.processor';

@Module({
    imports: [
        BullModule.registerAsync({
            imports: [ConfigModule],
            useExisting: BullConfigService,
        }),
    ],
    providers: [QueueJobProcessor],
})
export class AppModule {}

Example config file (async)

import { Injectable } from '@nestjs/common';
import { ConfigService } from './config.service';
import { BullModuleOptions, BullOptionsFactory } from '@mobizerg/nest-bull';

@Injectable()
export class BullConfigService implements BullOptionsFactory {

  constructor(private readonly config: ConfigService) {}

  createBullOptions(name?: string): BullModuleOptions {
      
    return {
      name,
      options: {
        redis: {
          host: this.config.redisHost,
          port: this.config.redisPort,
          db: this.config.redisDatabase,
          keyPrefix: this.config.redisPrefix + ':bull',
        },
        defaultJobOptions: {
          timeout: 30 * 1000,
          attempts: 2,
          backoff: {
            type: 'exponential',
            delay: 5 * 60 * 1000,
          },
        },
      },
    };
  }
}

Example usage inside services

import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@mobizerg/nest-bull';
import { Queue } from 'bull';

@Injectable()
export class BullService {

  constructor(@InjectQueue()
              private readonly queue: Queue) {}

  async addToQueue(data: T) {
    await this.queue.add(QUEUE_JOB_PROCESSOR, data);
  }
}

Example queue job processor

import { Injectable, OnModuleInit } from '@nestjs/common';
import { InjectQueue } from '@mobizerg/nest-bull';
import { Job, Queue } from 'bull';

@Injectable()
export class QueueJobProcessor implements OnModuleInit {

  constructor(@InjectQueue()
              private readonly queue: Queue) {}

  onModuleInit() {

    this.queue.process(QUEUE_JOB_PROCESSOR, (job: Job<T>) => {
      return 'completed';
    });
  }
}

License

MIT

Keywords

FAQs

Last updated on 17 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc