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

@monque/core

v1.2.0

Published

MongoDB-backed job scheduler with atomic locking, exponential backoff, and cron scheduling

Readme

A robust, type-safe MongoDB job queue for TypeScript with atomic locking, exponential backoff, and cron scheduling.

Features

  • 🔒 Atomic Locking: Mandatory findOneAndUpdate for safe job acquisition in distributed environments.
  • 📈 Exponential Backoff: Built-in retry logic with configurable backoff strategies.
  • 📅 Cron Scheduling: Native support for recurring jobs using standard cron syntax.
  • 🔍 Type Safety: Fully typed job payloads and worker definitions.
  • Event-Driven: Comprehensive event system for monitoring and logging.
  • 🛠️ Native Driver: Uses the native MongoDB driver for maximum performance and compatibility.
  • 🛑 Graceful Shutdown: Ensures all in-progress jobs finish or are safely released before stopping.

Installation

Using Bun:

bun add @monque/core mongodb

Or using npm/yarn/pnpm:

npm install @monque/core mongodb
yarn add @monque/core mongodb
pnpm add @monque/core mongodb

Usage

import { Monque } from '@monque/core';
import { MongoClient } from 'mongodb';

const client = new MongoClient('mongodb://localhost:27017');
await client.connect();

const monque = new Monque(client.db('myapp'), {
  collectionName: 'jobs',
  pollInterval: 1000,
  maxRetries: 10,
  defaultConcurrency: 5,
});

await monque.initialize();

// Register workers
monque.register('send-email', async (job) => {
  await sendEmail(job.data.to, job.data.subject);
});

// Start processing
monque.start();

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

// Schedule recurring jobs
await monque.schedule('0 9 * * *', 'daily-report', { type: 'summary' });

// Management
await monque.cancelJob('job-id');
const stats = await monque.getQueueStats();

// Graceful shutdown
await monque.stop();

API

new Monque(db, options?)

Creates a new Monque instance.

Options:

  • collectionName - MongoDB collection name (default: 'monque_jobs')
  • pollInterval - Polling interval in ms (default: 1000)
  • maxRetries - Max retry attempts (default: 10)
  • baseRetryInterval - Base backoff interval in ms (default: 1000)
  • shutdownTimeout - Graceful shutdown timeout in ms (default: 30000)
  • defaultConcurrency - Jobs per worker (default: 5)
  • lockTimeout - Stale job threshold in ms (default: 1800000)
  • recoverStaleJobs - Recover stale jobs on startup (default: true)

Methods

  • initialize() - Set up collection and indexes
  • enqueue(name, data, options?) - Enqueue a job
  • now(name, data) - Enqueue for immediate processing
  • schedule(cron, name, data) - Schedule recurring job
  • register(name, handler, options?) - Register a worker
  • start() - Start processing jobs
  • stop() - Graceful shutdown
  • isHealthy() - Check scheduler health

Management:

  • getJob(id) - Get job details
  • getJobs(filter) - List jobs
  • getJobsWithCursor(options) - Paginated list
  • getQueueStats(filter?) - Queue statistics
  • cancelJob(id) - Cancel a job
  • retryJob(id) - Retry a job
  • rescheduleJob(id, date) - Reschedule a job
  • deleteJob(id) - Delete a job
  • cancelJobs(filter) - Bulk cancel
  • retryJobs(filter) - Bulk retry
  • deleteJobs(filter) - Bulk delete

Events

monque.on('job:start', (job) => { /* job started */ });
monque.on('job:complete', ({ job, duration }) => { /* job completed */ });
monque.on('job:fail', ({ job, error, willRetry }) => { /* job failed */ });
monque.on('job:error', ({ error, job? }) => { /* unexpected error */ });
monque.on('job:cancelled', ({ job }) => { /* job cancelled */ });
monque.on('job:retried', ({ job, previousStatus }) => { /* job retried */ });
monque.on('job:deleted', ({ jobId }) => { /* job deleted */ });
monque.on('stale:recovered', ({ count }) => { /* stale jobs recovered */ });

Development

Running Tests

# Run tests once (fresh container each time)
bun run test

# Run tests in watch mode with container reuse (faster iteration)
bun run test:dev

# Or enable reuse globally in your shell profile
export TESTCONTAINERS_REUSE_ENABLE=true
bun run test:watch

When TESTCONTAINERS_REUSE_ENABLE=true, the MongoDB testcontainer persists between test runs, significantly speeding up local development. Ryuk (the testcontainers cleanup daemon) remains enabled as a safety net for orphaned containers.

To manually clean up reusable containers:

docker ps -q --filter label=org.testcontainers=true | while read -r id; do docker stop "$id"; done

License

ISC