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

snake-queue-job

v1.0.2

Published

[application._queueJob]

Downloads

6

Readme

CoilsQueueJob

[application._queueJob]

Install

npm i snake-queue-job -S

Usage

const redisClient = require('snake-redis').createClient()
const SnakeQueueJob = require('snake-queue-job')
const queueManager = new QueueManager({redis: redisClient})
# set status, default: quiet
await queueManager.changeStatus('quiet')
# default 15
await queueManager.changeConcurrency(19)
# minimum is 2 second, default 8
await queueManager.changePollingInterval(5)

options

  • redis: redis client, default: application._redis
  • path: default: app/jobs
  • namespace: default: _coils_jobs_

添加延时任务

# 10s 后执行 app/jobs目录下的HelloJob任务
queueManager.add('HelloJob').set({wait: 10}).perform_later('world-after1')

Jobs目录结构

  • In app/jobs/index.js write
const requireDirectory = require('require-directory')
module.exports = requireDirectory(module)

confirm install npm dependence: require-directory

  • app/jobs/HelloJob.js
class HelloJob {
	// 执行优先级
	static get priority () {
		return 'default' //default, allow [low, default, high]
	}
	// 总尝试次数
	static get totalTry () {
		return 5 //default 10
	}
	// 根据当前尝试次数,返回下一次尝试间隔
	static tryInterval (currentTry) {
		// default: currentTry * currentTry * currentTry * 10
		// second
		return 50
	}
	// 任务执行时候将调用此方法
	async perform () {
		console.log(arguments)
	}
}
module.exports = HelloJob

提示

同一时刻相同参数的任务只会被追加一次 eg: 同一时刻(年月日时分秒)调用两次任务

queueManager.add('HelloJob').set({wait: 40}).perform_later('world-after')
queueManager.add('HelloJob').set({wait: 40}).perform_later('world-after')

内部会根据当前时间,wait, args, jobName, priority, totalTry,... 生成一个唯一key, 相同的key会被忽略