Skip to content

Commit 83148bd

Browse files
docs(queue): name attribute outside factory for bull #2816
1 parent dbcc820 commit 83148bd

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

content/techniques/queues.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ export class AudioConsumer extends WorkerHost {
270270

271271
This is covered in the [named processor](https://docs.bullmq.io/patterns/named-processor) section of the BullMQ documentation.
272272

273-
274273
#### Request-scoped consumers
275274

276275
When a consumer is flagged as request-scoped (learn more about the injection scopes [here](/fundamentals/injection-scopes#provider-scope)), a new instance of the class will be created exclusively for each job. The instance will be garbage-collected after the job has completed.
@@ -320,15 +319,17 @@ You can see the complete list of events and their arguments as properties of Wor
320319
QueueEvent listeners must use the `@QueueEventsListener(queue)` decorator and extend the `QueueEventsHost` class provided by `@nestjs/bullmq`. To listen for an event, use the `@OnQueueEvent(event)` decorator with the event you want to be handled. For example, to listen to the event emitted when a job enters the active state in the `audio` queue, use the following construct:
321320

322321
```typescript
323-
import { QueueEventsHost, QueueEventsListener, OnQueueEvent } from '@nestjs/bullmq';
322+
import {
323+
QueueEventsHost,
324+
QueueEventsListener,
325+
OnQueueEvent,
326+
} from '@nestjs/bullmq';
324327

325328
@QueueEventsListener('audio')
326329
export class AudioEventsListener extends QueueEventsHost {
327330
@OnQueueEvent('active')
328-
onActive(job: { jobId: string; prev?: string; }) {
329-
console.log(
330-
`Processing job ${job.jobId}...`,
331-
);
331+
onActive(job: { jobId: string; prev?: string }) {
332+
console.log(`Processing job ${job.jobId}...`);
332333
}
333334

334335
// ...
@@ -450,6 +451,20 @@ BullModule.forRootAsync({
450451

451452
This construction works the same as `useClass` with one critical difference - `BullModule` will lookup imported modules to reuse an existing `ConfigService` instead of instantiating a new one.
452453

454+
Likewise, if you want to pass queue options asynchronously, use the `registerQueueAsync()` method, just keep in mind to specify the `name` attribute outside the factory function.
455+
456+
```typescript
457+
BullModule.registerQueueAsync({
458+
name: 'audio',
459+
useFactory: () => ({
460+
redis: {
461+
host: 'localhost',
462+
port: 6379,
463+
},
464+
}),
465+
});
466+
```
467+
453468
#### Bull installation
454469

455470
> warning **Note** If you decided to use BullMQ, skip this section and the following chapters.
@@ -845,7 +860,7 @@ export default function (job: Job, cb: DoneCallback) {
845860

846861
#### Async configuration
847862

848-
You may want to pass `bull` options asynchronously instead of statically. In this case, use the `forRootAsync()` method which provides several ways to deal with async configuration. Likewise, if you want to pass queue options asynchronously, use the `registerQueueAsync()` method.
863+
You may want to pass `bull` options asynchronously instead of statically. In this case, use the `forRootAsync()` method which provides several ways to deal with async configuration.
849864

850865
One approach is to use a factory function:
851866

@@ -910,6 +925,20 @@ BullModule.forRootAsync({
910925

911926
This construction works the same as `useClass` with one critical difference - `BullModule` will lookup imported modules to reuse an existing `ConfigService` instead of instantiating a new one.
912927

928+
Likewise, if you want to pass queue options asynchronously, use the `registerQueueAsync()` method, just keep in mind to specify the `name` attribute outside the factory function.
929+
930+
```typescript
931+
BullModule.registerQueueAsync({
932+
name: 'audio',
933+
useFactory: () => ({
934+
redis: {
935+
host: 'localhost',
936+
port: 6379,
937+
},
938+
}),
939+
});
940+
```
941+
913942
#### Example
914943

915944
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/26-queues).

0 commit comments

Comments
 (0)