Socket
Socket
Sign inDemoInstall

cron

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

52

lib/cron.js

@@ -279,15 +279,55 @@ var CronDate = Date;

if(this.running) return;
var MAXDELAY = 2147483647; // The maximum number of milliseconds setTimeout will wait.
var self = this;
var timeout = this.cronTime.getTimeout();
var remaining = 0;
if (this.cronTime.realDate) this.runOnce = true;
// The callback wrapper checks if it needs to sleep another period or not
// and does the real callback logic when it's time.
function callbackWrapper() {
// If there is sleep time remaining, calculate how long and go to sleep
// again. This processing might make us miss the deadline by a few ms
// times the number of sleep sessions. Given a MAXDELAY of almost a
// month, this should be no issue.
if (remaining) {
if (remaining > MAXDELAY) {
remaining -= MAXDELAY;
timeout = MAXDELAY;
} else {
timeout = remaining;
remaining = 0;
}
self._timeout = setTimeout(callbackWrapper, timeout);
} else {
// We have arrived at the correct point in time.
self.running = false;
//start before calling back so the callbacks have the ability to stop the cron job
if (!(self.runOnce)) self.start();
self._callback();
}
}
if (timeout >= 0) {
this.running = true;
this._timeout = setTimeout(function(self) {
self.running = false;
//start before calling back so the callbacks have the ability to stop the cron job
if (!(self.runOnce)) self.start();
// Don't try to sleep more than MAXDELAY ms at a time.
self._callback();
}, timeout, this);
if (timeout > MAXDELAY) {
remaining = timeout - MAXDELAY;
console.log('WARNING: timeout specified (' + timeout + ') was greater than the max of ' + MAXDELAY + '.');
timeout = MAXDELAY;
}
this._timeout = setTimeout(callbackWrapper, timeout);
} else {

@@ -294,0 +334,0 @@ this.stop();

2

package.json
{
"name": "cron",
"description": "CronJob's for your node",
"version": "0.3.3",
"version": "0.3.4",
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)",

@@ -6,0 +6,0 @@ "bugs" : {

@@ -296,3 +296,17 @@ var testCase = require('nodeunit').testCase,

}, 5250);
},
'test long wait should not fire immediately': function(assert) {
assert.expect(1);
var count = 0;
var d = new Date().getTime() + 31 * 86400 * 1000;
var job = cron.job(new Date(d), function() {
assert.ok(false);
});
job.start();
setTimeout(function() {
job.stop();
assert.ok(true);
assert.done();
}, 250);
}
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc