1.2.7 • Published 12 days ago

@anchan828/nest-bullmq v1.2.7

Weekly downloads
201
License
MIT
Repository
github
Last release
12 days ago

@anchan828/nest-bullmq

npm NPM

Description

The BullMQ module for Nest.

Installation

$ npm i --save @anchan828/nest-bullmq bullmq

Quick Start

Import BullModule

import { BullModule } from "@anchan828/nest-bullmq";
import { Module } from "@nestjs/common";

@Module({
  imports: [
    BullModule.forRoot({
      options: {
        connection: {
          host: "127.0.0.1",
        },
      },
    }),
  ],
})
export class AppModule {}

Create queue provider

import { Module } from "@nestjs/common";
import { ExampleService } from "./example.service";
import { APP_QUEUE } from "./app.constants";

@Module({
  imports: [BullModule.registerQueue(APP_QUEUE)],
  providers: [ExampleService],
})
export class ExampleModule {}

With queue options

import { Module } from "@nestjs/common";
import { ExampleService } from "./example.service";
import { APP_QUEUE } from "./app.constants";

@Module({
  imports: [
    BullModule.registerQueue({
      queueName,
      options: {
        defaultJobOptions: { priority: 1 },
      },
    }),
  ],
  providers: [ExampleService],
})
export class ExampleModule {}

Inject Queue provider

import { Inject, Injectable } from "@nestjs/common";
import { Queue } from "bullmq";
import { APP_QUEUE } from "./app.constants";
import { BullQueueInject } from "@anchan828/nest-bullmq";

@Injectable()
export class ExampleService {
  constructor(
    @BullQueueInject(APP_QUEUE)
    private readonly queue: Queue,
  ) {}

  async addJob(): Promise<Job> {
    return this.queue.add("example", { text: "text" });
  }
}

Create worker provider

import { BullWorker, BullWorkerProcess } from "@anchan828/nest-bullmq";
import { APP_QUEUE } from "./app.constants";

@BullWorker({ queueName: APP_QUEUE })
export class ExampleBullWorker {
  @BullWorkerProcess()
  public async process(job: Job): Promise<{ status: string }> {
    return { status: "ok" };
  }
}

Add Worker/Queue/QueueEvents listeners

Listeners can be added via the decorator.

Worker listeners

All event names can be found here.

import { BullWorker, BullWorkerProcess, BullWorkerListener, BullWorkerListenerArgs } from "@anchan828/nest-bullmq";
import { APP_QUEUE } from "./app.constants";

@BullWorker({ queueName: APP_QUEUE })
export class ExampleBullWorker {
  @BullWorkerProcess()
  public async process(job: Job): Promise<{ status: string }> {
    return { status: "ok" };
  }

  @BullWorkerListener("completed")
  public async completed(job: BullWorkerListenerArgs["completed"]): Promise<void> {
    calledEvents("completed");
    console.debug(`[${job.id}] completed`);
  }
}

Queue listeners

All event names can be found here.

import { BullQueue, BullQueueListener, BullQueueListenerArgs } from "@anchan828/nest-bullmq";
import { APP_QUEUE } from "./app.constants";

@BullQueue({ queueName: APP_QUEUE })
export class ExampleBullQueue {
  @BullQueueListener("waiting")
  public async waiting(job: BullQueueListenerArgs["waiting"]): Promise<void> {
    calledEvents("waiting");
    console.debug(`[${job.id}] waiting`);
  }
}

QueueEvents listeners

All event names can be found here.

import { BullQueueEvents, BullQueueEventsListener, BullQueueEventsListenerArgs } from "@anchan828/nest-bullmq";
import { APP_QUEUE } from "./app.constants";

@BullQueueEvents({ queueName: APP_QUEUE })
export class ExampleBullQueueEvents {
  @BullQueueEventsListener("added")
  public async added(args: BullQueueEventsListenerArgs["added"]): Promise<void> {
    console.debug(`[${args.jobId}] added`);
  }

  @BullQueueEventsListener("active")
  public async active(args: BullQueueEventsListenerArgs["active"]): Promise<void> {
    console.debug(`[${args.jobId}] active`);
  }

  @BullQueueEventsListener("completed")
  public async completed(args: BullQueueEventsListenerArgs["completed"]): Promise<void> {
    console.debug(`[${args.jobId}] completed`);
  }

  @BullQueueEventsListener("waiting")
  public async waiting(args: BullQueueEventsListenerArgs["waiting"]): Promise<void> {
    console.debug(`[${args.jobId}] waiting`);
  }
}

Examples

There are examples.

License

MIT

1.2.7

12 days ago

1.2.6

19 days ago

1.2.5

26 days ago

1.2.4

1 month ago

1.2.0

2 months ago

1.2.3

1 month ago

1.2.2

2 months ago

1.2.1

2 months ago

1.1.8

2 months ago

1.1.7

2 months ago

1.1.6

2 months ago

1.1.5

3 months ago

1.1.4

3 months ago

1.1.3

3 months ago

1.0.22

6 months ago

1.0.26

5 months ago

1.0.25

5 months ago

1.0.24

5 months ago

1.0.23

6 months ago

1.0.29

4 months ago

1.0.28

4 months ago

1.0.27

5 months ago

1.0.31

4 months ago

1.0.30

4 months ago

1.1.1

3 months ago

1.1.0

3 months ago

1.1.2

3 months ago

1.0.19

6 months ago

1.0.18

7 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.15

7 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.5.33

11 months ago

0.5.32

11 months ago

0.5.31

11 months ago

0.5.30

12 months ago

0.5.29

12 months ago

0.5.28

12 months ago

0.5.27

1 year ago

0.5.26

1 year ago

0.5.25

1 year ago

0.5.23

1 year ago

0.5.24

1 year ago

0.5.22

1 year ago

0.5.21

1 year ago

0.5.20

1 year ago

0.5.19

1 year ago

0.5.18

1 year ago

0.5.17

1 year ago

0.5.16

1 year ago

0.5.15

1 year ago

0.5.14

1 year ago

0.5.13

1 year ago

0.5.12

1 year ago

0.5.11

1 year ago

0.5.10

1 year ago

0.5.9

1 year ago

0.5.8

1 year ago

0.5.7

1 year ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.0

1 year ago

0.4.18

1 year ago

0.4.17

1 year ago

0.4.16

1 year ago

0.4.15

2 years ago

0.4.14

2 years ago

0.4.13

2 years ago

0.4.12

2 years ago

0.4.11

2 years ago

0.4.10

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.40

2 years ago

0.3.38

2 years ago