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

qos

v0.3.1

Published

Safe, fast and super simple queue and schedule based on Redis.

Downloads

44

Readme

qos

Safe, fast and super simple queue and schedule based on Redis.

QoS (Queue or Schedule) offers a simple api for scheduling and running tasks in background. QoS is build on top of Redis. It's super fast and it uses atomic commands to ensure safe job execution in cluster environments.

Setup

$ npm install --save qos

Usage

Before we start make sure you have Redis server up and running.

Queue

Let's create a new file ./index.js and define a simple queue.

import Redis from 'ioredis';
import qos from 'qos';

// initializing redis instance
const redis = new Redis();

// initializing handler for processing jobs
const handler = data => {
  console.log(`Handling job named ${data.name}`);
};

// initializing queue named `myqueue`
const queue = new qos.Queue(redis, 'myqueue', handler);

// starting queue
queue.start();

First we need to pass an instance of a Redis connection to the Queue class. QoS should work with any Redis library that supports promises. The second argument is the name of the queue. The last argument is a function for processing jobs.

We are now ready to enqueue a job using the enqueue command.

queue.enqueue({name: 'JobName'}); // returns a Promise

The enqueue command is actually a call to the handler. It accepts an argument which is passed directly to the handler.

We can also remove a job using the dequeue command.

queue.dequeue({name: 'JobName'}); // returns a Promise

Jobs can also be executed without touching the queuing system using the perform method.

queue.perform({name: 'JobName'}); // returns a Promise

Schedule

To schedule a job at a particular time in the future we need to use the Schedule class. Schedule is an extended Queue class. It has pretty much the same logic. The main difference is that we need to provide some additional information for the enqueue and dequeue commands.

Let's open our ./index.js file which we defined earlier and add a scheduler.

let schedule = new qos.Schedule(redis, 'myschedule'); // you can set the default `queue` through options which is optional third parameter

schedule.start();

Schedule a job with the delay of 10s.

schedule.enqueue({
  queue, // you can also pass queue name (e.g. 'myqueue')
  at: Date.now() + 10000,
  data: {name: 'JobName'} // Queue job data
}); // returns a Promise

There is one important different between Queue and Schedule classes. If we call the command above multiple times, an existing job will be replaced with a new one. This means that two identical jobs can not exist in scheduled queue. This is great and ensures that the same job will never accidentally be scheduled twice.

Scheduled jobs can also be removed.

schedule.dequeue({
  queue,
  data: {name: 'JobName'}
}); // returns a Promise

We can also check if the job is schedule by using the isEnqueued command.

schedule.isEnqueued({
  queue,
  data: {name: 'JobName'}
}); // returns a Promise

There is also a toggle command which enqueues/dequeues a job based on an optional condition.

let condition = 1 > 0;
schedule.toggle({
  queue,
  at: Date.now() + 10000,
  data: {name: 'JobName'}
}, condition); // returns a Promise

Example

You can run the attached example with the npm run example command.