Browse files

Merged down master. Also, removed logging and updated ignore.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent d72fde9 commit 8983ae0b576b449db15f75e5985a39328bf72348 @ncb000gt committed Oct 20, 2011
Showing with 16 additions and 15 deletions.
  1. +1 −1 .gitignore
  2. +15 −14 lib/cron.js
View
2 .gitignore
@@ -1,2 +1,2 @@
-*.swp
+*.sw[a-z]
node_modules
View
29 lib/cron.js
@@ -84,7 +84,7 @@ CronTime.prototype = {
* Get the number of seconds in the future at which to fire our callbacks.
*/
getTimeout: function() {
- return Math.max(0, this.sendAt().getTime() - Date.now());
+ return Math.max(-1, this.sendAt().getTime() - Date.now());
},
/**
@@ -205,7 +205,6 @@ function CronJob(cronTime, onTick, onComplete) {
this.cronTime = new CronTime(cronTime);
this.addCallback(onTick);
-
this.start();
}
@@ -223,7 +222,7 @@ CronJob.prototype = {
*/
_callback: function() {
- for (var i = this._callbacks.length; i--;) {
+ for (var i = (this._callbacks.length - 1); i >= 0; i--) {
//send this so the callback can call this.stop();
this._callbacks[i].call(this, this.onComplete);
@@ -235,21 +234,22 @@ CronJob.prototype = {
* Start the cronjob.
*/
start: function() {
-
if(this.running) return;
- this.running = true;
+ var timeout = this.cronTime.getTimeout();
- this._timeout = setTimeout(function(self)
- {
-
- self.running = false;
-
- //start before calling back so the callbacks have the ability to stop the cron job
- self.start();
+ if (timeout >= 0) {
+ this.running = true;
+ this._timeout = setTimeout(function(self) {
+ self.running = false;
- self._callback();
- }, this.cronTime.getTimeout(), this);
+ //start before calling back so the callbacks have the ability to stop the cron job
+ self.start();
+ self._callback();
+ }, timeout, this);
+ } else {
+ this.running = false;
+ }
},
/**
@@ -258,6 +258,7 @@ CronJob.prototype = {
stop: function()
{
clearTimeout(this._timeout);
+ //if (this.onComplete) this.onComplete();
}
};

0 comments on commit 8983ae0

Please sign in to comment.