Registry / devops / mongo-queue

mongo-queue

JSON →
library1.0.0jsnpmunverified

A MongoDB-backed job queue for Node.js, inspired by Resque. Version 1.0.0. The library ensures no jobs are lost even if the application crashes by keeping jobs in the database until workers complete them successfully. It supports job expiration, timeouts, max attempts, delayed execution, and parallel workers. Unlike many job queues, it emphasizes reliability over performance, making it suitable for critical tasks. The API includes Connection, Template, and Worker classes. The project appears inactive (last release in 2013).

devops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The package is written in CoffeeScript and provides a default export. In Node.js, require('mongo-queue') returns the module, which contains Connection, Template, and Worker as properties. Use const mq = require('mongo-queue'); then new mq.Connection(). For ESM, there is no named export; use default import.

import mongoQueue from 'mongo-queue'; const connection = new mongoQueue.Connection();

Template is a CoffeeScript class; extend it to define job perform() and complete() methods. The library uses CoffeeScript's class inheritance; if using JavaScript, you must call Template.call(this) in constructor or use ES6 class extension which works because CoffeeScript classes are compatible.

import mongoQueue from 'mongo-queue'; class MyJob extends mongoQueue.Template { ... }

Worker constructor expects connection (instance of Connection), an array of Template subclasses, and an options object. Common mistake: passing job instances instead of classes.

import mongoQueue from 'mongo-queue'; const worker = new mongoQueue.Worker(connection, [MyJob], options);

Shows how to create a job template, connect to MongoDB, enqueue a job, and start a worker to process jobs.

import mongoQueue from 'mongo-queue'; class Addition extends mongoQueue.Template { perform(a, b) { console.log(a + ' + ' + b + ' = ' + (a + b)); this.complete(); } } const connection = new mongoQueue.Connection({ host: 'localhost', port: 27017, db: 'test' }); connection.on('error', err => console.error('Connection error:', err)); connection.on('connected', () => { console.log('Connected to MongoDB'); // Enqueue a job connection.enqueue('calculations', 1, 2, (err, job) => { if (err) return console.error('Enqueue error:', err); console.log('Job enqueued:', job._id); }); // Start worker const worker = new mongoQueue.Worker(connection, [Addition], { timeout: 1000, rotate: false, workers: 3 }); worker.on('error', err => console.error('Worker error:', err)); worker.on('drained', () => console.log('Queue empty')); worker.on('stopped', () => console.log('Worker stopped')); worker.poll(); }); connection.on('error', err => console.error('Error:', err));
Debug
Known footguns
gotchaThe library uses CoffeeScript; jobs must call this.complete() explicitly or they will remain locked.
deprecatedMongoDB native driver version used may be very old; recent MongoDB versions may require driver >= 3.x.
gotchaConnection constructor accepts both a string (database name) and a MongoDB Db object. Using a string creates a new connection; using an existing Db object can lead to unexpected behavior if that connection is closed.
gotchaThe 'drained' event may fire on every poll when queue is empty, causing continuous events in a fast-polling setup.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
ahrefsbot
1
Resources