DailyJS

Agenda: Lightweight Job Scheduling

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

node modules npm

Agenda: Lightweight Job Scheduling

Posted by Alex R. Young on .
Featured

node modules npm

Agenda: Lightweight Job Scheduling

Posted by Alex R. Young on .

Agenda (GitHub: rschmukler / agenda, License: MIT, npm: agenda) by Ryan Schmukler is a job scheduler for Node that uses MongoDB as the backend. It runs periodically, so you'd need to run it as a background process on something like Heroku or Nodejitsu.

You can control the number of concurrent jobs with the concurrency option, and jobs can be given a priority so higher priority jobs can run first.

Basic usage looks like this:

agenda.define('delete old users', function(job, done) {  
  User.remove({lastLogIn: { $lt: twoDaysAgo }}, done);
});

agenda.every('3 minutes', 'delete old users');

agenda.every('*/3 * * * *', 'delete old users');

agenda.start();  

The last example looks like cron, so you can use it as a cron replacement if you're used to that syntax. The agenda.start method kicks off the process so jobs will run.

The MongoDB instance can be specified using the database method, and configuration options can be chained:

var agenda = new Agenda();  
agenda  
  .database(...)
  .processEvery('3 minutes')

Agenda was recently featured as an npmawesome post on Nodejitsu's blog: Schedule regular jobs with agenda.