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).

npm install mongo-queue
INSTALL
IMPORT
SIG · MONGO-QUEUE
M
mongo-queue
devopsjavascriptv1.0.0
harness data pending
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.

Connection
import mongoQueue from 'mongo-queue'; const connection = new mongoQueue.Connection();
const { Connection } = require('mongo-queue'); const connection = new Connection();
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.
Template
import mongoQueue from 'mongo-queue'; class MyJob extends mongoQueue.Template { ... }
const mongoQueue = require('mongo-queue'); class MyJob extends mongoQueue.Template { ... }
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.
Worker
import mongoQueue from 'mongo-queue'; const worker = new mongoQueue.Worker(connection, [MyJob], options);
const { Worker } = require('mongo-queue'); const worker = new Worker(connection, [MyJob], options);
Worker constructor expects connection (instance of Connection), an array of Template subclasses, and an options object. Common mistake: passing job instances instead of classes.

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 issues
gotchaThe library uses CoffeeScript; jobs must call this.complete() explicitly or they will remain locked.
fix
Always call this.complete() in your perform() method after job work is done, even if there's an error (pass error as argument).
affects: >=1.0.0
deprecatedMongoDB native driver version used may be very old; recent MongoDB versions may require driver >= 3.x.
fix
Pin mongodb driver to a compatible version (e.g., 1.4.x) or migrate to a maintained queue library.
affects: >=1.0.0
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.
fix
Always pass a string for db unless you have a specific reason to reuse a Db instance. If reusing, ensure the Db connection remains open.
affects: >=1.0.0
gotchaThe 'drained' event may fire on every poll when queue is empty, causing continuous events in a fast-polling setup.
fix
Implement a flag to ignore 'drained' events after the first, or increase poll timeout.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: Worker is not defined
Not importing the Worker property from the default export.
fix
Use const mongoQueue = require('mongo-queue'); const Worker = mongoQueue.Worker;
TypeError: this.complete is not a function
Job class not properly extending mongoQueue.Template or missing method definition.
fix
Ensure your job class extends mongoQueue.Template and calls this.complete() correctly. In ES6 classes, you must call super() in constructor if you define one.
MongoError: auth failed
Authentication parameters provided but connection options missing username/password.
fix
Verify username and password in the Connection options. Also ensure MongoDB server requires authentication.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
mongodbrequirednative MongoDB driver for database operations
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
mongo-queue — npm install mongo-queue · libregistry