Git Product home page Git Product logo

egg-bull's Introduction

egg-bull

NPM version npm download

bull plugin for Egg.js.

安装

$ npm install -S @hackycy/egg-bull bull
$ npm install --save-dev @types/bull

插件内并无直接依赖bull,需要自己安装

使用

插件启用

// {app_root}/config/plugin.ts
const plugin: EggPlugin = {
  bull: {
    enable: true,
    package: '@hackycy/egg-bull',
  },
}

定义Queue

app目录新建queue目录,所有的Queue都要在该文件夹下定义,注意返回的类型一定要为bull实例,否则使用该插件无意义。这里只是约定。

// app/queue/task.ts
import * as Queue from 'bull';
import { Application } from 'egg';

export default (app: Application) => {
  app.logger.info('queue');
  const q = new Queue('testqueue', {
    redis: {
      port: 6379,
      host: '127.0.0.1',
      password: '123456',
      db: 0,
    },
  });
  q.process(function(job, done) {
    app.logger.info('[queue]', job.data);
    done();
  });
  return q;
};

可以以文件夹分隔。

建议export导出为一个funtion,这样会注入一个Egg的Application实例。

如无需使用Application实例的可以直接导出定义的bull实例。

该插件辅助定义了egg-ts-helper,可以在TS项目中方便使用。

获取Queue

已经将所有定义的Queue挂载到了Application上,例如获取上述定义的

this.app.queue.task.add({ b: 'a' }); //具体使用与bull无差异

有问题或Bug

请提出issues

License

MIT

egg-bull's People

Contributors

hackycy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.