Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/owl1n/nest-queue
Queue manager for NestJS Framework for Redis (via bull package)
https://github.com/owl1n/nest-queue
bull job job-scheduler nest nestjs queue redis typescript
Last synced: 2 months ago
JSON representation
Queue manager for NestJS Framework for Redis (via bull package)
- Host: GitHub
- URL: https://github.com/owl1n/nest-queue
- Owner: owl1n
- License: mit
- Created: 2019-04-22T13:52:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T20:16:56.000Z (almost 2 years ago)
- Last Synced: 2024-09-27T07:01:25.854Z (3 months ago)
- Topics: bull, job, job-scheduler, nest, nestjs, queue, redis, typescript
- Language: TypeScript
- Homepage: https://nestjs.com/
- Size: 1.92 MB
- Stars: 71
- Watchers: 4
- Forks: 5
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nestjs - Nest Queue - 基于 Redis 的简单队列管理,适用于您的应用程序。 (资源 / 组件和库)
README
## Queue manager for NestJS applications
Easy for use and installation into you'r projects.`yarn add nest-queue`
Make sure you have installed redis on your host. For local development you can easily install it using [docker](https://hub.docker.com/_/redis/).
*For better working you need to use `nest` package with `6.*.*` ver.*
#### How to1) Add new module in your `app.module.ts` file:
*This module (QueueModule) marked as global.*
```typescript
import { Module } from '@nestjs/common';
import { QueueModule } from 'nest-queue';
@Module({
imports: [
QueueModule.forRoot({}),
]
})
export class AppModule {}
```
For first parameter `forRoot` function accept options for current module.
Settings very simply and have this structure:
```typescript
export interface QueueModuleOptions {
name?: string,
connection?: Bull.QueueOptions,
}
```
For connection settings you can take help from [Bull documentation](https://optimalbits.github.io/bull/).
By default connection setting is:
```
connection: {
redis: {
port: 6379,
}
}
```It means we will work with `localhost:6379` host.
2) Add queue and handle events
For add job to queue u need inject a Queue instance into your service or controller.
For example:```typescript
import { Controller, Get } from '@nestjs/common'
import { Queue } from 'bull';
import { QueueInjection } from 'nest-queue';@Controller('test')
class TestController {
constructor(
@QueueInjection() private readonly queue: Queue,
) {}
@Get('/')
index() {
this.queue.add('testEvent', { data: 1, somedata: 2 });
}
}
```In this case you can manipulate with job adding. You can add delayed call and etc.
Information about it you can take from [Bull documentation](https://optimalbits.github.io/bull/).Anywhere (controllers, services) in your project you can provide event handler for redis calls.
`@EventConsumer(eventName)` method decorator allows you to work with it. For example:
```typescript
import { Job, DoneCallback } from 'bull';
import { EventConsumer } from 'nest-queue';
class TestService {
@EventConsumer('testEvent')
eventHandler(job: Job, done: DoneCallback) {
// job.data has passed data from queue adding
done(); // required call to stop job
}
}
```
*Context (this) in this function equals to TestService prototype with all resolved dependencies*
Function that will provide as event handler receive two arguments `Job` and `DoneCallback`.
This function calls as bull-processors and you can take help about from bull [Bull documentation](https://optimalbits.github.io/bull/).#### Future Goals
* Add tests;
* Async module adding;
* Workaround with bull and provide once module for manipulating with jobs;
* Add console commands lika a `queue list` and etc for receiving information about
all processing jobs and allow to restart failed jobs (like a Laravel artisan queue manager).#### Contributors
* [Maxim Markin](https://github.com/owl1n)