0.3.7 • Published 7 years ago

monq v0.3.7

Weekly downloads
331
License
MIT
Repository
github
Last release
7 years ago

monq

Monq is a MongoDB-backed job queue for Node.js.

NPM Build Status

API Reference

Usage

Connect to MongoDB by specifying a URI or providing host, port and database options:

var monq = require('monq');
var client = monq('mongodb://localhost:27017/monq_example');

Enqueue jobs by supplying a job name and a set of parameters. Below, the job reverse is being placed into the example queue:

var queue = client.queue('example');

queue.enqueue('reverse', { text: 'foobar' }, function (err, job) {
    console.log('enqueued:', job.data);
});

Create workers to process the jobs from one or more queues. The functions responsible for performing a job must be registered with each worker:

var worker = client.worker(['example']);

worker.register({
    reverse: function (params, callback) {
        try {
            var reversed = params.text.split('').reverse().join('');
            callback(null, reversed);
        } catch (err) {
            callback(err);
        }
    }
});

worker.start();

Events

Workers will emit various events while processing jobs:

worker.on('dequeued', function (data) { … });
worker.on('failed', function (data) { … });
worker.on('complete', function (data) { … });
worker.on('error', function (err) { … });

Install

npm install monq

Tests

npm test

You can optionally specify the MongoDB URI to be used for tests:

MONGODB_URI=mongodb://localhost:27017/monq_tests npm test

Updating API documentation

npm run jsdoc2md

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

8 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago