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

distributed-job-queue

v1.1.0

Published

A fast and robust job processing system based on Redis

Downloads

8

Readme

Distributed Job Queue

What is Distributed Job Queue?

Distributed Job Queue is a Node.js library that provides a fast and robust job processing system based on Redis.

While it is possible to implement queues using raw Redis commands, this library offers an API that abstracts away the low-level details and enhances Redis's basic functionality. This allows you to handle more complex use cases with ease.

This project is heavily inspired by Bull.

Getting Started

Distributed Job Queue is available as a public npm package and can be installed using npm

$ npm install distributed-job-queue --save

Queues

A queue is simply created by instantiating a Queue instance:

const myFirstQueue = new Queue('my-first-queue');

A queue instance can normally have 2 main roles: A job producer and job consumer.

The producer and consumer can divided into several instances. A given queue, always referred to by its instantiation name ( my-first-queue in the example above ), can have many producers and consumers. An important aspect is that producers can add jobs to a queue even if there are no consumers available at that moment: queues provide asynchronous communication, which is one of the features that makes them so powerful.

Conversely, you can have one or more workers consuming jobs from the queue, which will consume the jobs in a given order: FIFO or according to priorities.

Producers

A job producer is a Node.js program that adds jobs to a queue:

const jobData = {
    task: 'sendEmail',
    to: '[email protected]',
    subject: 'Welcome!',
    body: 'Hello, welcome to our service!',
};

const jobOptions = {
    priority: 1, // Lower number means higher priority
    attempts: 3, // Number of retry attempts if the job fails
};

myFirstQueue.addJobs(jobData, jobOptions)

A job is simply a JavaScript object that needs to be serializable (i.e., JSON stringify-able) to be stored in Redis. You can also provide an options object with additional job settings.

Consumers

A consumer, or worker, is a Node.js program that defines a process function to handle jobs:

burgerQueue.processJobs((job, done) => {
   doSomething(job)
}, 5);

The process function is called whenever the worker is idle and there are jobs to process. The queue could have many jobs waiting, and the process function will be busy processing them one by one until all are completed.