Skip to content

Commit

Permalink
feat(bullmq): extend configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfachHans authored and Romakita committed Nov 20, 2023
1 parent 732232f commit e7099a3
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 166 deletions.
49 changes: 35 additions & 14 deletions docs/tutorials/bullmq.md
Expand Up @@ -12,7 +12,7 @@ meta:

## Feature

The [BullMQ](https://bullmq.io) Module for Ts.ED allows you to decorate a class using the `@Job` decorator and implement the `Job` interface provided by the module.
The [BullMQ](https://bullmq.io) Module for Ts.ED allows you to decorate a class using the `@JobController` decorator and implement the `JobMethods` interface provided by the module.
Repeatable Jobs can also be defined using this decorator.

For more information about BullMQ look at the documentation [here](https://docs.bullmq.io/);
Expand All @@ -35,24 +35,40 @@ import "@tsed/bullmq"; // import bullmq ts.ed module

@Configuration({
bullmq: {
queues: ["default", "special"];
// Specify queue name's to create
queues: ["default", "special"],
connection: {
// redisio connection options
};
// optional default job options
defaultJobOptions: {};
disableWorker: false;
// optionally specify for which queues to start a worker for
// in case not all queues should be worked on
workerQueues: ["default"];
},
defaultQueueOptions: {
// Default queue options which are applied to every queue
// Can be extended/overridden by `queueOptions`
},
queueOptions: {
special: {
// Specify additional queue options by queue name
}
},
// Specify for which queues to start a worker for.
// Defaultly for every queue added in the `queues` parameter
workerQueues: ["default"],
defaultWorkerOptions: {
// Default worker options which are applied to every worker
// Can be extended/overridden by `workerOptions`
},
workerOptions: {
special: {
// Specify additional worker options by queue name
}
}
}
})
export class Server {}
```

## Define a Job

A job is defined as a class decorated with the `@Job` decorator and implementing the `Job` interface of the `@tsed/bullmq` package
A job is defined as a class decorated with the `@JobController` decorator and implementing the `Job` interface of the `@tsed/bullmq` package

```ts
import {JobController, JobMethods} from "@tsed/bullmq";
Expand Down Expand Up @@ -82,7 +98,8 @@ class OtherExampleJob implements JobMethods {

## Defining a repeating job

Jobs that should be run regularly on a schedule can also easily defined using the `@Job` decorator
Jobs that should be run regularly on a schedule can also easily defined using the `@JobController` decorator.
Doing so will automatically dispatch it without any data.

```ts
import {JobController, JobMethods} from "@tsed/bullmq";
Expand Down Expand Up @@ -146,9 +163,13 @@ class MyService {
constructor(private readonly dispatcher: JobDispatcher) {}

public async doingSomething() {
await this.dispatcher.dispatch(ExampleJob, {msg: "this message is part of the payload for the job"}, {
delay: 600_000 // 10 minutes in milliseconds
});
await this.dispatcher.dispatch(
ExampleJob,
{msg: "this message is part of the payload for the job"},
{
delay: 600_000 // 10 minutes in milliseconds
}
);

console.info("I just dispatched a job!");
}
Expand Down
37 changes: 27 additions & 10 deletions packages/third-parties/bullmq/README.md
Expand Up @@ -33,7 +33,7 @@ A package of Ts.ED framework. See website: https://tsed.io

## Feature

The `@tsed/bullmq` package allows you to define jobs using the `@Job` decorator and the `JobMethods` interface and have them picked up by the `BullMQ` worker.
The `@tsed/bullmq` package allows you to define jobs using the `@JobController` decorator and the `JobMethods` interface and have them picked up by the `BullMQ` worker.

## Installation

Expand All @@ -53,16 +53,32 @@ import "@tsed/bullmq"; // import bullmq ts.ed module

@Configuration({
bullmq: {
queues: ["default", "special"];
// Specify queue name's to create
queues: ["default", "special"],
connection: {
// redisio connection options
};
// optional default job options
defaultJobOptions: {};
disableWorker: false;
// optionally specify for which queues to start a worker for
// in case not all queues should be worked on
workerQueues: ["default"];
},
defaultQueueOptions: {
// Default queue options which are applied to every queue
// Can be extended/overridden by `queueOptions`
},
queueOptions: {
special: {
// Specify additional queue options by queue name
}
},
// Specify for which queues to start a worker for.
// Defaultly for every queue added in the `queues` parameter
workerQueues: ["default"],
defaultWorkerOptions: {
// Default worker options which are applied to every worker
// Can be extended/overridden by `workerOptions`
},
workerOptions: {
special: {
// Specify additional worker options by queue name
}
}
}
})
export class Server {}
Expand Down Expand Up @@ -100,7 +116,8 @@ class OtherExampleJob implements JobMethods {

## Defining a repeating job

Jobs that should be run regularly on a schedule can also easily defined using the `@AsJob` decorator
Jobs that should be run regularly on a schedule can also easily defined using the `@JobController` decorator.
Doing so will automatically dispatch it without any data

```ts
import {JobController, JobMethods} from "@tsed/bullmq";
Expand Down
2 changes: 1 addition & 1 deletion packages/third-parties/bullmq/jest.config.js
Expand Up @@ -2,7 +2,7 @@ module.exports = {
...require("@tsed/jest-config"),
coverageThreshold: {
global: {
branches: 82.85,
branches: 86.48,
functions: 100,
lines: 100,
statements: 100
Expand Down

0 comments on commit e7099a3

Please sign in to comment.