Skip to content

Instantly share code, notes, and snippets.

@onewland
Forked from fwg/cron-test.js
Created November 18, 2009 21:35
Show Gist options
  • Save onewland/238286 to your computer and use it in GitHub Desktop.
Save onewland/238286 to your computer and use it in GitHub Desktop.
corrected cron.js
// Sample for http://oliveriskindoffunny.tumblr.com/post/247975858/implementing-a-user-friendly-cron-module-with-node-js
var cron = require('./cron'), sys = require('sys');
cron.Every((2).seconds(), function() { sys.puts('Working!'); });
// Sample for http://oliveriskindoffunny.tumblr.com/post/247975858/implementing-a-user-friendly-cron-module-with-node-js
function TimeInterval() {
this.seconds = 0;
this.addTo = function(ti) {
this.seconds += ti.seconds;
return this;
};
}
function generate_multiplier(multiplier)
{
return function() {
var interval = new TimeInterval(); // use var keyword!
interval.seconds = this * multiplier;
return interval;
};
}
Number.prototype.seconds = generate_multiplier(1);
Number.prototype.minutes = generate_multiplier(60);
Number.prototype.hours = generate_multiplier(3600);
exports.Every = function(timeInterval, callback) {
setInterval(callback, timeInterval.seconds * 1000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment