-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(nestjs): add queue events listeners section
- Loading branch information
1 parent
75dd80b
commit d82fdcc
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Queue Events Listeners | ||
|
||
To register a QueueEvents instance, you need to use **QueueEventsListener** decorator: | ||
|
||
```typescript | ||
import { | ||
QueueEventsListener, | ||
QueueEventsHost, | ||
OnQueueEvent, | ||
} from '@nestjs/bullmq'; | ||
|
||
@QueueEventsListener('queueName') | ||
export class TestQueueEvents extends QueueEventsHost { | ||
@OnQueueEvent('completed') | ||
onCompleted({ | ||
jobId, | ||
}: { | ||
jobId: string; | ||
returnvalue: string; | ||
prev?: string; | ||
}) { | ||
// do some stuff | ||
} | ||
} | ||
``` | ||
|
||
And then register it as a provider: | ||
|
||
```typescript | ||
@Module({ | ||
imports: [ | ||
BullModule.registerQueue({ | ||
name: 'queueName', | ||
connection: { | ||
host: '0.0.0.0', | ||
port: 6380, | ||
}, | ||
}), | ||
], | ||
providers: [TestQueueEvents], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
## Read more: | ||
|
||
- 💡 [Queues Technique](https://docs.nestjs.com/techniques/queues) | ||
- 💡 [Register Queue API Reference](https://nestjs.bullmq.pro/classes/BullModule.html#registerQueue) | ||
- 💡 [Queue Events Listener API Reference](https://api.docs.bullmq.io/interfaces/v4.QueueEventsListener.html) |