firstandthird / hapi-job-queue

Hapi and MongoDB powered job queue.
MIT License
3 stars 1 forks source link
hapi-plugin

hapi-job-queue

Hapi and MongoDB powered job queue.

Build Status Coverage Status

Features:

Install:

npm install hapi-job-queue --save

Usage:

var server = new Hapi.Server();
var mongoUrl = 'mongodb://localhost:27017/something';

server.connection({port: 3000});

server.method('emailUsers', function(data, done) {
  server.plugins.emailService.spam(data.group, done);
});

server.register([
  { register: require('hapi-job-queue'), options: {
    connectionUrl: mongoUrl,
    endpoint: '',
    jobs: [
      {
        name: 'email-users',
        enabled: true,
        schedule: 'on the last day of the month',
        method: 'emailUsers', //server method
        tasks: [ // each task will run 'emailUsers' with the task as the data property
          {
            group: 'pendingUsers'
          },
          {
            group: 'approvedUsers'
          },
          {
            group: 'newsletterUsers'
          }
        ]
      }
    ]
  } }
], function() {
  // server start etc...
});

Options:

Methods:

These methods can be found in server.plugins.jobs.

API

If you enable the web api these endpoints will be exposed.