Scheduling events in the future with Meteor (Email example)


Having just implemented a server-side task scheduler with Meteor that allows the user to schedule a given task to take place exactly once in the future, and then answered a question on the same subject on Stack Overflow, I thought I’d share my method here.


As the number of Meteor packages on Atmosphere increases exponentially, one of the best guarantees of quality is the percolate namespace. They’ve released the excellent synced-cron package, which is far more powerful than the requirements of this use case, but it still works better than any other package I’ve come across.

$ meteor add percolate:synced-cron

Set up your task and a schedule collection

Set up a server-side collection to store your tasks in case of server reboot, and the body of the task you want to complete (in this case, sending an email).

FutureTasks = new Meteor.Collection('future_tasks'); // server-side only

// In this case, "details" should be an object containing a date, plus required e-mail details (recipient, content, etc.)

function sendMail(details) {

		from: details.from,


Add functions to schedule and record your tasks

function addTask(id, details) {

		name: id,
		schedule: function(parser) {
			return parser.recur().on(;
		job: function() {
	        	return id;


function scheduleMail(details) { 

	if ( < new Date()) {
	} else {
		var thisId = FutureTasks.insert(details);
		addTask(thisId, details);		
	return true;


Process existing tasks on reboot, and start the Cron

Meteor.startup(function() {

	FutureTasks.find().forEach(function(mail) {
		if ( < new Date()) {
		} else {
			addTask(mail._id, mail);


Then, you can just call scheduleMail from the server whenever you want to add a new task to the queue.


Hopefully, the code above is straightforward, as is the path to generalising to other use cases beyond sending email. If there are any questions or suggestions, just let me know.