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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-taskman

v2.1.1

Published

Fast work queue based on redis.

Readme

node-taskman

Build Status Dependency Status devDependency Status

node-taskman is a fast work queue based on redis.

Core features:

Install

npm install node-taskman

Usage

var taskman = require('node-taskman');

// Process tasks.
var worker = taskman.createWorker('email');
worker.process(function sendEmail(emails, done) {
  // send emails
  done();
});

// Create tasks.
var queue = taskman.createQueue('email');
queue.push({to: '[email protected]', body: 'Hello world!'});

Worker

taskman.createWorker(name, options)

Create a new worker to process tasks.

Arguments:

  {string} name Name of the task to process.
  {object} options Options.
  {number} options.batch Number of tasks popped in each tick (default 1).
  {string} options.name Name of the worker (default os.hostname()).
  {number} options.ping Internal ping interval in ms (default 1000).
  {number} options.sleep Sleep time between each tick in ms (default 0)   
  {object|function} options.redis Redis configuration.
  {string} options.type Type of worker, 'fifo' or 'lifo' (default 'fifo').
  {boolean} options.unique Unique queue or not (default false).
// Create a new worker that sleep 2s between each task.
var worker = taskman.createWorker('email', {sleep: 2000});

worker.process(action)

Process tasks. The action has two arguments, first is the tasks, the number depends of the batch option. The second is the callback, if it's called with an error, a "job failure" event is emitted, else a "job complete" event is emitted.

worker.process(function (tasks, done) {
 // process tasks
});

worker.set(options, [callback])

Update options of the worker.

Arguments:

  {object} options Options.
  {number} options.batch Number of tasks popped in each tick.
  {number} options.ping Internal ping interval in ms.
  {number} options.sleep Sleep time between each tick in ms.
  {object|function} options.redis Redis configuration.
  {string} options.type Type of worker, 'fifo' or 'lifo'.
  {function} [callback] Optional callback.
// Put worker in lifo mode.
worker.set({type: 'lifo'});

worker.get(callback)

Get informations about the worker.

worker.get(function (err, infos) {
  console.log(infos); // worker infos
});

worker.close([options], [callback])

Gracefully stop the worker.

Arguments:

  {object} [options] Optional options.
  {boolean} options.queue Close the worker queue (default true).
  {function} [callback] Optional callback.
worker.close(function (err) {
  // worker closed
});

Events

"error"

Emitted when:

  • a callback is omitted and an error occur in a method
  • a redis "error" event is emitted
worker.on('error', function (error) {
  // ...
});
"job failure"

Emitted when an error is returned by the job process.

worker.on('job failure', function (task, error) {
  // ...
});
"job complete"

Emitted when a job is completed without error.

worker.on('job complete', function (task) {
  // ...
});
"status change"

Emitted when the worker status change.

worker.on('status change', function (status) {
  // ...
});

Queue

taskman.createQueue(name, options)

Create a new queue to add task.

Arguments:

  {string} name Name of the task to process.
  {object} options Options.
  {object|function} options.redis Redis configuration.
  {boolean} options.unique Unique queue or not (default false).
// Create a new unique queue.
var queue = taskman.createQueue('email', {unique: true});

queue.push(task)

Push a new task at the end of the queue.

queue.push({to: '[email protected]', body: 'Hello world!'});

queue.close([callback])

Close the connection to the queue, the redis command used is QUIT, so it will wait that all redis commands are done before closing the connection. The queue will continue to persist so tasks will not be lost.

Arguments:

  {function} [callback] Optional callback.
queue.close(function (err) {
  // queue closed
});

Events

"error"

Emitted when:

  • a callback is omitted and an error occur in a method
  • a redis "error" event is emitted
queue.on('error', function (error) {
  // ...
});
"created"

Emitted when a new task is created.

queue.on('created', function (task) {
  // ...
});

Features

Atomicity

Every tasks are added and removed using redis transactions. You can't be stuck in an unstable state.

Persistence

Thanks to redis, it's possible to choose the level of persistence of your queue.

Hot configuration

Workers configuration (batch, ping, sleep) is stored in a redis hash. If you change this redis hash, the changes will be active without the need to reload your workers.

The redis hash name is "worker:{queueName}:{workerName}".

You will find some informations like:

  • createdAt: creation date of the worker
  • pid: process identifier
  • batch: number of tasks processed at each tick
  • ping: ping time
  • sleep: sleep time
  • type: type of worker (fifo or lifo)
  • queue: name of the queue
  • taskCount: number of tasks already processed
  • status: status of the worker (waiting, working, stopped)

Unique tasks

If you choose the unique mode, every tasks added in the queue will be present once at a time X. This feature is very interesting if you need to add task that consume a lot of resources. To known if the task is unique or not we compare all the payload of the task.

Multi tasks processing

Using the configuration "batch" it's possible to specify the number of tasks processed at each tick. This feature is interesting if you need to batch some tasks in a single request (insert in database, indexing...).

License

MIT

Credits

Written and maintained by Greg Bergé and Justin Bourrousse.

An original idea by David Desbouis.

Built an used at Le Monde.