GithubHelp home page GithubHelp logo

owl1n / nest-queue Goto Github PK

View Code? Open in Web Editor NEW
70.0 4.0 5.0 1.97 MB

Queue manager for NestJS Framework for Redis (via bull package)

Home Page: https://nestjs.com/

License: MIT License

TypeScript 100.00%
nestjs queue redis job job-scheduler bull typescript nest

nest-queue's Introduction

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.

For better working you need to use nest package with 6.*.* ver.

How to

  1. Add new module in your app.module.ts file:

    This module (QueueModule) marked as global.

    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:

    export interface QueueModuleOptions {
       name?: string,
       connection?: Bull.QueueOptions,
    }

    For connection settings you can take help from Bull documentation. 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:

    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.

    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:

    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.

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

nest-queue's People

Contributors

dengnan123 avatar dependabot[bot] avatar owl1n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nest-queue's Issues

UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object

Here is some of my information

error message

(node:98239) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at instanceWrappers.map (/Users/dany/Desktop/工作/dfocus-remind-backend-system/node_modules/nest-queue/dist/queue.provider.js:45:46)
    at Array.map (<anonymous>)
    at QueueProvider.getEventConsumers (/Users/dany/Desktop/工作/dfocus-remind-backend-system/node_modules/nest-queue/dist/queue.provider.js:44:14)
    at QueueModule.onModuleInit (/Users/dany/Desktop/工作/dfocus-remind-backend-system/node_modules/nest-queue/dist/queue.module.js:34:41)
    at Object.callModuleInitHook (/Users/dany/Desktop/工作/dfocus-remind-backend-system/node_modules/@nestjs/core/hooks/on-module-init.hook.js:42:35)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
(node:98239) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:98239) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

app.module.ts

import { Module } from '@nestjs/common';
import { QueueModule } from 'nest-queue';
// import { AppController } from './app.controller';
// import { AppService } from './app.service';

@Module({
  imports: [
    QueueModule.forRoot({
      name: 'meeting',
      connection: {
        redis: {
          port: 6379,
        },
      },
    }),
  ],
  // controllers: [AppController],
  // providers: [AppService],
})
export class AppModule {}

pkg

    "@nestjs/bull": "0.0.1-beta.4",
    "@nestjs/common": "^6.0.0",
    "@nestjs/core": "^6.0.0",
    "@nestjs/platform-express": "^6.0.0",
    "bull": "^3.12.1",
    "nest-queue": "^1.0.3",

Please help me see,thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.