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

queue-runtime

v0.1.2

Published

A powerful, flexible multi-queue job processing runtime with global worker pool, automatic worker redistribution, and support for multiple queue drivers (Redis, RabbitMQ, AWS SQS, Memory)

Readme

Queue Runtime

A powerful, flexible multi-queue job processing runtime with global worker pool, automatic worker redistribution, and support for multiple queue drivers.

Features

Core Features

  • Multi-queue support - Manage multiple job queues independently
  • Global worker pool - Shared worker pool across all queues with maxWorkers limit
  • Per-queue concurrency limits - Control concurrency for each queue
  • Worker redistribution - Automatically redistribute idle workers to busy queues
  • Rebalancing on release - Rebalance workers when queues become idle
  • Graceful shutdown - Wait for running jobs to complete before shutdown

Error Handling

  • Retry mechanism - Automatic retry with exponential backoff
  • Dead Letter Queue (DLQ) - Failed jobs after max attempts sent to DLQ
  • Error tracking - Track and report errors with detailed statistics

Queue Drivers

  • Redis - Production-ready Redis driver (default)
  • RabbitMQ - RabbitMQ driver (optional dependency)
  • AWS SQS - AWS SQS driver (optional dependency)

Installation

npm install queue-runtime

Optional Dependencies

For RabbitMQ support:

npm install amqplib @types/amqplib

For AWS SQS support:

npm install @aws-sdk/client-sqs

Quick Start

import { RedisDriver, QueueRuntime } from 'queue-runtime';
// Or import drivers separately:
// import { RedisDriver } from 'queue-runtime/drivers/redis';

// Create driver
const driver = new RedisDriver('redis://localhost:6379');
await driver.connect();

// Create runtime
const runtime = new QueueRuntime(driver, {
  maxWorkers: 15,
  enableRedistributeIdleWorkers: true,
  enableRebalanceOnRelease: true,
  pollInterval: 50,
});

// Register jobs
runtime.registerJob({
  queueName: 'send-email',
  concurrency: 8,
  maxAttempts: 3,
  handler: async (payload) => {
    // Your job logic here
    console.log('Sending email to:', payload.to);
  },
});

// Enqueue jobs
await runtime.enqueue('send-email', { to: '[email protected]' });

// Start processing
runtime.start();

Configuration

QueueRuntimeConfig

interface QueueRuntimeConfig {
  maxWorkers: number;                    // Maximum workers across all queues
  enableRedistributeIdleWorkers?: boolean; // Auto-redistribute idle workers (default: true)
  enableRebalanceOnRelease?: boolean;    // Rebalance when queue releases workers (default: true)
  pollInterval?: number;                 // Polling interval in ms (default: 50)
  errorHandler?: ErrorHandlerConfig;     // Error handling configuration
}

JobDefinition

interface JobDefinition {
  queueName: string;                    // Unique queue name
  concurrency: number;                  // Max concurrent jobs for this queue
  handler: (payload: any) => Promise<any>; // Job handler function
  maxAttempts?: number;                // Max retry attempts (default: 3)
  retryBackoffMs?: number;              // Base retry delay (default: 1000ms)
  retryBackoffMultiplier?: number;      // Exponential backoff multiplier (default: 2)
  maxRetryDelayMs?: number;             // Max retry delay (default: 300000ms = 5min)
  dlqEnabled?: boolean;                 // Enable dead letter queue (default: true)
}

Queue Drivers

Redis Driver

import { RedisDriver } from 'queue-runtime/drivers/redis';

const driver = new RedisDriver('redis://localhost:6379');
await driver.connect();

RabbitMQ Driver

import { RabbitMQDriver } from 'queue-runtime';
// Or: import { RabbitMQDriver } from 'queue-runtime/drivers/rabbitmq';

const driver = new RabbitMQDriver({
  url: 'amqp://localhost',
  durable: true,
  prefetch: 1,
});
await driver.connect();

AWS SQS Driver

import { SQSDriver } from 'queue-runtime';
// Or: import { SQSDriver } from 'queue-runtime/drivers/sqs';

const driver = new SQSDriver({
  region: 'us-east-1',
  accessKeyId: 'your-key',
  secretAccessKey: 'your-secret',
});
await driver.connect();

Memory Driver (Testing)

import { MemoryDriver } from 'queue-runtime';
// Or: import { MemoryDriver } from 'queue-runtime/drivers/memory';

const driver = new MemoryDriver();
await driver.connect();

Statistics & Monitoring

// Get runtime statistics
const stats = runtime.getStats();
console.log(stats);
// {
//   maxWorkers: 15,
//   globalPool: 5,
//   available: 10,
//   queues: [...],
//   errors: { totalErrors: 0, errorsByQueue: {}, errorsByType: {} }
// }

// Get error reports
const errors = runtime.getErrorReports(10); // Last 10 errors

Error Handling

Jobs automatically retry on failure with exponential backoff. After max attempts, jobs are sent to a Dead Letter Queue (DLQ).

runtime.registerJob({
  queueName: 'process-order',
  concurrency: 5,
  maxAttempts: 3,
  retryBackoffMs: 1000,        // Start with 1 second
  retryBackoffMultiplier: 2,   // Double each retry: 1s, 2s, 4s
  maxRetryDelayMs: 30000,      // Max 30 seconds
  dlqEnabled: true,            // Send to DLQ after max attempts
  handler: async (payload) => {
    // Your job logic
  },
});

Worker Redistribution

The runtime automatically redistributes idle workers to busy queues:

  • Idle Worker Redistribution: When total concurrency < maxWorkers, idle workers are distributed evenly across queues
  • Rebalance on Release: When a queue releases all workers, they're redistributed to other active queues

License

MIT

Requirements

  • Node.js >= 18