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 🙏

© 2026 – Pkg Stats / Ryan Hefner

distributed-task

v0.0.3

Published

`distributed-task` provides a framework upon which one can easily build distributed task systems in Node. The original reason for building a new distributed task system was to allow 'watching' of tasks, specifically long/indefinitely running tasks. `distr

Readme

Node Distributed Task

distributed-task provides a framework upon which one can easily build distributed task systems in Node. The original reason for building a new distributed task system was to allow 'watching' of tasks, specifically long/indefinitely running tasks. distributed-task consistes of a few features:

  • Redis as a global state store
  • distributor
    • handle the distribution of tasks
    • read incoming tasks from a Redis queue
    • monitors its own set of tasks
    • monitor all tasks on longer interval
  • worker
    • has tasks as Node functions w/JSON config
    • does the actual task work
    • connects to the distributors
    • updates task info in Redis
    • listens for watcher connections
  • watcher
    • talks direct to workers and can subscribe/unsubscribe to task live related events
    • gets task/worker info from Redis

Synopsis

Config.json
{
    "share_key": "abc",
    "key": "test/tls/key.pem",
    "cert": "test/tls/certificate.pem",
    "redis": {
        "host": "localhost",
        "port": 6379
    },
    "host": "localhost",
    "port": 5000,
    "distributors": [
        ["localhost", 5000]
    ]
}
distributor.js
#!/usr/bin/env node

var distributor = require('../distributed-task/distributor');
distributor.init(require('./config.json'));
worker.js
#!/usr/bin/env node

var worker = require('../distributed-task/worker');
worker.init(require('./config.json'));
worker.addTask('name', someFunction);

Full Example

A full example (almost deploy ready) can be found here.

Definitions

Task

{
    clean_end: true,      // allow distributors to clean up the task when it ends (& loose end status)
    state_optional: true; // allow the task to continue running when Redis goes down
                          // shouldn't happen but no guarantee the task won't also be requeued w/ multiple distributors-over-WAN
                          // it basically assumes all distributors share the same connection to Redis
}

Task Status

  • RUNNING - task is running, should have updated timestamp
  • STOPPED - task stopped intentionally by distributor/worker loosing related worker/distributor connection
  • END - task is complete, pending cleanup

Redis Bits

  • new-task - simple list based queue
  • tasks - set of all task_id's
  • task-<uuid> - individual task details

Failover/HA

  • A shorter loop is recommended for workers than distributors
  • All distributors/workers must have the same timezone set
  • Distributors/workers send health checks to each other according to a configured time interval
  • Both distributor and worker acknowledge disconnect on stream close + after missed health check
    • distributor flags worker as down and clears after interval, will requeue tasks
    • worker stops running tasks for this distributor (which should requeue them)
  • Upon disconnect from Redis: workers, for each connected distributor:
    • notify the distributor, which stops sending new task requests
    • pause running distributor tasks
    • check if we're connected to the distributor
    • if so, assumes distributor has also lost Redis connection & won't requeue
    • continue distributor tasks w/o state_optional = true
    • stop all other tasks from this distributor
  • Distributors watch for tasks w/ state STOPPED & RUNNING w/out of date timestamp, requeues
  • Same as above for END tasks with clean_end = true
  • Distributors watch their own tasks on a short interval, and all tasks on a long interval
  • Upon reconnect to Redis, workers check state_optional task timestamps before updating, and stop if newer one