Agenda: Lightweight Job Scheduling

2014-05-16 00:00:00 +0100 by Alex R. Young

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');


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();
  .processEvery('3 minutes')

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