npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-bulls

v1.1.22

Published

egg.js的Bull插件

Downloads

57

Readme

egg-bulls

NPM version build status Test coverage David deps Known Vulnerabilities npm download

安装

$ npm i egg-bulls --save

依赖说明

依赖的 egg 版本

| egg-bulls 版本 | egg 2.x | | -------------- | ------- | | 1.x | 😁 |

依赖的插件

| egg-bulls 版本 | Bull | | -------------- | ----- | | 1.x | 3.6.x |

更多 Bull.js 的信息请 点击

使用场景

  • 在 egg.js 中使用 Bull.js

开启插件

// {app_root}/config/plugin.js
exports.bulls = {
  enable: true,
  package: "egg-bulls"
};

插件配置

单实例

// {app_root}/config/config.default.js
exports.bulls = {
  client: {
    topic: "queue",
    queueOptions: {
      redis: {
        host: "localhost",
        port: 6379,
        db: 0,
        password: "Pass1234"
      }
    }
  }
};

多实例

// {app_root}/config/config.default.js
exports.bulls = {
  clients: {
    queue1: {
      // topic must same with key
      topic: "queue1",
      queueOptions: {
        redis: {
          host: "localhost",
          port: 6379,
          db: 1,
          password: "Pass1234"
        }
      }
    },
    queue2: {
      // topic must same with key
      topic: "queue2",
      queueOptions: {
        redis: {
          host: "localhost",
          port: 6379,
          db: 2,
          password: "Pass1234"
        }
      }
    }
  }
};

或者使用相同的 Redis 配置

// Use the same redis configuration
exports.bulls = {
  clients: {
    queue1: { topic: "queue1" },
    queue2: { topic: "queue2" }
  },
  default: {
    queueOptions: {
      redis: {
        host: "localhost",
        port: 6379,
        db: 0,
        password: "Pass1234"
      }
    }
  }
};

更多配置请查看 config/config.default.js

示例

文件挂载路径为{app_root}/app/{topic},在 app 上访问 app[topic]

单实例

// 配置

// topic 默认为 queue 时,如果使用自定义名称挂载路径变为{app_root}/app/{topic}

// {app_root}/config/config.default.js
exports.bulls = {
  client: {
    topic: "queue",
    redis: {
      host: "localhost",
      port: 6379,
      db: 0,
      password: "Pass1234"
    }
  }
};
// 可以直接在 app 上使用
app.bulls.process(job => {
  console.log(job.data.job1); // 'this is a job'
});
app.bulls.add({ job1: "this is a job" });
app.bulls.on('completed', (job)=>{
//  do something
})
app.bulls.on('failed', (err,job)=>{
// do something
});

// 或者批量添加

// {app_root}/app.js
class AppBootHook{
  constructor(app){
    this.app = app
  }
  async didReady(){
    const jobs = [{
      // topic:queue
      queue:'queue'
      data:{
        // job data
      },
      jobName:'job-Name',
      options:{
        // job options
      }
    }];
    await this.app.addJobtToQueue(jobs)
  }
}
// {app_root}/app/queue/status.js
module.exports = app => {
  return {
    completed(job) {
      // do something
    }
    failed(job,error){
      // do something
    }
    //
    // use async
    //
    async completed(job) {
      // do something
    }
    async failed(job,error){
      // do something
    }
  };
};
// {app_root}/app/queue/handle.js
module.exports = app => {
  return job => {
    // do something
  }
};



// topic 为自定义时

// {app_root}/config/config.default.js
exports.bulls = {
  client: {
    topic: "test",
    redis: {
      host: "localhost",
      port: 6379,
      db: 0,
      password: "Pass1234"
    }
  }
};

// 可以直接在 app 上使用
app.bulls.process(job => {
  console.log(job.data.job1); // 'this is a job'
});
app.bulls.add({ job1: "this is a job" });
app.bulls.on('completed', (job)=>{
//  do something
})
app.bulls.on('failed', (err,job)=>{
// do something
});

// 或者

// {app_root}/app.js
class AppBootHook{
  constructor(app){
    this.app = app
  }
  async didReady(){
    const jobs = [{
      // topic:test
      queue:'test'
      data:{
        // job data
      },
      jobName:'job-Name',
      options:{
        // job options
      }
    }];
    await this.app.addJobtToQueue(jobs)
  }
}

// {app_root}/app/test/status.js
module.exports = app => {
  return {
    completed(job) {
      // do something
    }
    failed(job,error){
      // do something
    }
    //
    // use async
    //
    async completed(job) {
      // do something
    }
    async failed(job,error){
      // do something
    }
  };
};
// {app_root}/app/test/handle.js
module.exports = app => {
  return job => {
    // do something
  }
};

多实例

// 配置

// {app_root}/config/config.default.js
exports.bulls = {
  clients: {
    queue1: {
      topic: "queue1",
      redis: {
        host: "localhost",
        port: 6379,
        db: 1,
        password: "Pass1234"
      }
    },
    queue2: {
      topic: "queue2",
      redis: {
        host: "localhost",
        port: 6379,
        db: 2,
        password: "Pass1234"
      }
    }
  }
};
// 可以直接在 app 上使用
app.bulls.get("queue1").process(job => {
  console.log(job.data.job1); // 'this is a job1'
});
app.bulls.get("queue2").process(job => {
  console.log(job.data.job2); // 'this is a job2'
});

app.bulls.get("queue1").add({ job1: "this is a job1" });
app.bulls.get("queue2").add({ job2: "this is a job2" });

// 或者

// {app_root}/app.js
class AppBootHook{
  constructor(app){
    this.app = app
  }
  async didReady(){
    const jobs = [{
      data:{
        // job data
      },
      jobName:'job-Name1',
      options:{
        // job options
      },
      // topic:queue1
      queue:'queue1'
    },{
      data:{
        // job data
      },
      jobName:'job-Name2',
      options:{
        // job options
      },
      // topic: queue1
      queue:'queue2'
    }];
    await this.app.addJobtToQueue(jobs)
  }
}

// {app_root}/app/queue1/status.js
module.exports = app => {
  return {
    completed(job) {
      // do something
    }
    failed(job,error){
      // do something
    }
    //
    // use async
    //
    async completed(job) {
      // do something
    }
    async failed(job,error){
      // do something
    }
  };
};
// {app_root}/app/queue2/status.js
module.exports = app => {
  return {
    completed(job) {
      // do something
    }
    failed(job,error){
      // do something
    }
    //
    // use async
    //
    async completed(job) {
      // do something
    }
    async failed(job,error){
      // do something
    }
  };
};
// {app_root}/app/queue1/handle.js
module.exports = app => {
  return job => {
    // do something
  }
};
// {app_root}/app/queue2/handle.js
module.exports = app => {
  return job => {
    // do something
  }
};

提问交流

请到 egg-bulls issues 异步交流。

License

MIT