0.3.1 • Published 5 years ago

nestjsx-bull v0.3.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Description

This is a Bull module for Nest.

Installation

$ npm i --save nestjsx-bull bull
$ npm i --save-dev @types/bull

Quick Start

import { Body, Controller, Get, Module, Param, Post } from "@nestjs/common";
import { DoneCallback, Job, Queue } from "bull";
import { BullModule, InjectQueue } from "nest-bull";

// BullModule is global, so it can be used anywhere,
// not just under ApplicationModule
@Controller()
export class AppController {
  constructor(@InjectQueue("store") readonly queue: Queue) {}

  @Post()
  async addJob(@Body() value: any) {
    const job: Job = await this.queue.add(value);
    return job.id;
  }

  @Get(":id")
  async getJob(@Param("id") id: string) {
    return await this.queue.getJob(id);
  }
}

@Module({
  imports: [
    BullModule.forRoot({
        queues: [
            name: "store",
            options: {
                redis: {
                port: 6379
                }
            },
            processors: [
                (job: Job, done: DoneCallback) => {
                    done(null, job.data);
                }
            ]
        ]
    })
  ],
  controllers: [AppController]
})
export class ApplicationModule {}

People