Skip to content

Instantly share code, notes, and snippets.

@prestonp
Created April 14, 2014 17:27
Show Gist options
  • Save prestonp/10667484 to your computer and use it in GitHub Desktop.
Save prestonp/10667484 to your computer and use it in GitHub Desktop.
scheduler example

Declare actions.js

var scheduler = require('../lib/scheduler');
scheduler.registerAction('make-call', function(job, done) {
  twilio.makeCall(job.data, function(error) {
    if (error) {
      logger.error('Could not place call for job #' + job.id, error);
      done('failed');
    } else {
      logger.info('Made call successfully', job);
      done('completed');
    }
  });
});

In worker

var require('./actions');
var require('./scheduler');

scheduler.runAll(function(error, stats){
  // stats => { started: 2, completed: 0, failed: 2 }
});

So to implement more scheduled events we would just registerAction() and enqueue jobs. The worker would pretty much just run all registered actions and format the stats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment