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

@fangcha/resque

v1.8.0

Published

Node resque.

Downloads

37

Readme

node-resque

一些设计

  • 这是一个轻量级的任务处理模块,基本设定与 resque/resque 一致,可通过 resque-web 进行任务管理
  • 采用 redis blpop 的方式等待任务而非轮询
  • 目前单个程序只支持串行处理任务,可通过多个程序达到并发效果;后续将直接支持任务并发

运行要求

  • node
  • redis

安装

npm install @fangcha/resque

使用

配置示例

const config = {
  logFile: `${__dirname}/run.local/resque.log`,
  pidFile: `${__dirname}/run.local/resque.pid`,
  redisConfig: {
    redisHost: '127.0.0.1',
    redisPort: 6379,
  },
  moduleMapFile: `${__dirname}/task-map.js`,
  queues: [
    'TaskQueueDemo',
  ]
}

module.exports = config

定义启动脚本

脚本示例,参考 launcher-demo,可保存为 ./node-resque

#!/usr/bin/env node

const { FCLauncher } = require('@fangcha/resque')

const launchFile = process.argv[1]
const cmd = process.argv[2] ? process.argv[2] : ''

const launcher = new FCLauncher(launchFile, config)
launcher.handle(cmd)
./node-resque start

启动后,将根据 config 配置生成 pid 文件及日志文件

命令支持: start / stop / restart / status

定义任务

  • 任务必须为一个继承于 IResqueTask 的类,并实现 async perform(params) 方法,参考 TaskDemo
  • 需要在 config.moduleMapFile 中添加对自定义任务的引用
  • config.queues 中定义任务队列监听的 queue 名称
// TaskDemo.js
const { IResqueTask } = require('@fangcha/resque')

class TaskDemo extends IResqueTask {
  async perform(params) {
    // do something
  }
}

module.exports = TaskDemo

moduleMapFile

参考本工程的 task-map.jsTaskDemo 即代表了任务类

module.exports = {
  TaskDemo: require('./TaskDemo')
}

异步任务入队

const { Resque } = require('@fangcha/resque')

Resque.setRedisBackend(config.redisConfig)

...

await Resque.enqueue('TaskQueueDemo', 'TaskDemo', params)

您可以参考 tests/resque 中的代码