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-queue

v1.0.4

Published

kue plugin for egg

Downloads

10

Readme

egg-queue

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

Install

$ npm i egg-queue --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.queue = {
     register: true, //是否注册事件(queue和主工程分开,可以两个docker运行)
     listen: 7002,  //kue默认提供了一个[UI](https://github.com/Automattic/kue/blob/master/Readme.md#user-interface)
     prefix: 'kuequeue',
     redis: {
        port: 6379, // Redis port
        host: 'myredis', // Redis host
        password: null,
        db: 2,
     },
};

see config/config.default.js for more detail.

Example

这里注册task可以使用两种形式

  1. 导出一个函数
// app/queue/send_sms.js

'use strict';

module.exports = {

  /**
     * 执行queue中的任务
     * @param {Object} ctx egg中的ctx,方便访问egg中的资源
     * @param {Object} job kue中的job
     * @param {Object} kueCtx kue中的ctx,可以控制任务的暂停,重启
     * @param {function}  done 任务完成成功done(),失败done(err)
     * @return {void}
     */
  async task(ctx, job, kueCtx, done) {
    console.log(job);
    done();
  },

  /**
     *添加到queue中的标志
     *可选,默认action为js文件名 send_sms.js => sendSms
     * @return {string} action
     */
  get action() {
    return 'send_sms';
  },

  /**
     *任务的并发量
     *可选,默认为1
     * @return {number} concurrency
     */
  get concurrency() {
    return 2;
  },
};
  1. 导出一个class
// app/queue/send_sms3.js
'use strict';

const Subscription = require('egg').Subscription;

class SmsSendSubscription extends Subscription {

  /**
     * 执行queue中的任务,this 为egg的ctx
     * @param {Object} job kue中的job
     * @param {Object} kueCtx kue中的ctx,可以控制任务的暂停,重启
     * @param {function}  done 任务完成成功done(),失败done(err)
     * @return {void}
     */
  async subscribe(job, kueCtx, done) {
    setTimeout(() => {
      done();
    }, 5000);
  }


  /**
     *添加到queue中的标志
     *可选,默认action为js文件名 send_sms.js => sendSms
     * @return {string} action
     */
  static get action() {
    return 'send_sms3';
  }

  /**
     *任务的并发量
     *可选,默认为1
     * @return {number} concurrency
     */
  get concurrency() {
    return 2;
  }

}

module.exports = SmsSendSubscription;

发布task

    const { queue } = ctx.app;

    const res = await queue.create('send_sms3', {
      phone: '139********',
    }).save();

queue即为kue中的queue

Questions & Suggestions

Please open an issue here.

License

MIT