Code Monkey home page Code Monkey logo

monq's Introduction

monq

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

NPM Build Status

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

monq's People

Contributors

scttnlsn avatar scriby avatar oomathias avatar saintedlama avatar dhritzkiv avatar fastman avatar mdellanoce avatar santinell avatar mamboer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.