mr-wolf

0.1.1 • Public • Published

mr-wolf

Distributed work-queue for nodejs

Installation

$ npm install mr-wolf

Usage

Create a job

Place your work in the default /jobs-directory. Note that you can change the location of this directory using

 
mrWolf.setJobDirectory('./some/other/place');
 

example: /jobs/sendEmail.js

 
module.exports = {
  //A job must implement the receive-method that takes two parameters
  //meta : the meta-data sent to the job
  //callback : a callback with one parameter : error (if any)
  receive : function(meta, callback) {
    sendEmail(meta.recipient, meta.title, meta.body, function(err) {
      callback(err);
    });
  }
};
 

Enqueue a work-item

 
var mrWolf = require('mr-wolf');
//Push takes two arguments, 
//the job-name (should be equivalent to the fileName mentioned in create a job)
//and the meta-data, which will also be supplied to the job.
mrWolf.enqueue('sendEmail', {
  recipient : "mr.recipient@coolmail.com",
  title : 'Hello mr!',
  body : 'Its a fifteen minute drive, I\'ll be there in five'
});
 

Start working

Note that starting mr-wolf on many servers lets them share the work-load and process the queue faster.

Here's how you get start it up:

 
mrWolf.start({
  //Add some listeners (optional)
  onError : function(job, error) { },
  onStart : function(job) { },
  onComplete : function(job) { },
  onEnqueue : function(job) { }
});

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i mr-wolf

    Weekly Downloads

    0

    Version

    0.1.1

    License

    none

    Last publish

    Collaborators

    • julian