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 1.0.0 to 1.0.1

18

lib/cron.js

@@ -47,3 +47,3 @@ var CronDate = Date;

//add 1 second so next time isn't now (can cause timeout to be 0)
date.setSeconds(date.getSeconds() + 1);
if (!(this.realDate)) date.setSeconds(date.getSeconds() + 1);

@@ -235,3 +235,3 @@ if (this.realDate) {

function CronJob(cronTime, onTick, onComplete, start, timeZone) {
function CronJob(cronTime, onTick, onComplete, start, timeZone, context) {
if (typeof cronTime != "string" && arguments.length == 1) {

@@ -241,2 +241,3 @@ //crontime is an object...

onComplete = cronTime.onComplete;
context = cronTime.context;
start = cronTime.start;

@@ -249,2 +250,3 @@ timeZone = cronTime.timeZone;

this.context = (context || this);
this._callbacks = [];

@@ -277,7 +279,16 @@ this.onComplete = onComplete;

//send this so the callback can call this.stop();
this._callbacks[i].call(this, this.onComplete);
this._callbacks[i].call(this.context, this.onComplete);
}
},
/**
* Manually set the time of a job
*/
setTime: function(time) {
if (!(time instanceof CronTime)) throw '\'time\' must be an instance of CronTime.';
this.stop();
this.cronTime = time;
},
/**

@@ -336,3 +347,2 @@ * Start the cronjob.

remaining = timeout - MAXDELAY;
console.log('WARNING: timeout specified (' + timeout + ') was greater than the max of ' + MAXDELAY + '.');
timeout = MAXDELAY;

@@ -339,0 +349,0 @@ }

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

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

@@ -12,2 +12,8 @@ node-cron

If You Are Submitting Bugs/Issues
=============
Because we can't magically know what you are doing to expose an issue, it is best if you provide a snippet of code. This snippet need not include your secret sauce, but it must replicate the issue you are describing. The issues that get closed without resolution tend to be the ones without code examples. Thanks.
Versions and Backwards compatability breaks:

@@ -121,3 +127,3 @@ ==========

* `constructor(cronTime, onTick, onComplete, start)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
* `constructor(cronTime, onTick, onComplete, start, timezone, context)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
* `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.

@@ -127,2 +133,4 @@ * `onTick` - [REQUIRED] - The function to fire at the specified time.

* `start` - [OPTIONAL] - Specifies whether to start the job after just before exiting the constructor.
* `timezone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone.
* `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
* `start` - Runs your job.

@@ -129,0 +137,0 @@ * `stop` - Stops your job.

@@ -174,6 +174,4 @@ var testCase = require('nodeunit').testCase,

});
c.start();
setTimeout(function() {
c.start();
}, 1000);
setTimeout(function() {
assert.done();

@@ -183,3 +181,3 @@ }, 3250);

'test specifying a specific date': function(assert) {
assert.expect(1);
assert.expect(2);
var prepDate = new Date();

@@ -197,2 +195,4 @@ if ((58 - prepDate.getSeconds()) <= 0) {

var c = new cron.CronJob(d, function() {
var t = new Date();
assert.equal(t.getSeconds(), d.getSeconds());
assert.ok(true);

@@ -207,3 +207,3 @@ }, null, true);

'test specifying a specific date with oncomplete': function(assert) {
assert.expect(2);
assert.expect(3);
var prepDate = new Date();

@@ -221,2 +221,4 @@ if ((58 - prepDate.getSeconds()) <= 0) {

var c = new cron.CronJob(d, function() {
var t = new Date();
assert.equal(t.getSeconds(), d.getSeconds());
assert.ok(true);

@@ -335,3 +337,73 @@ }, function() {

}, 250);
},
'test start, change time, start again': function(assert) {
assert.expect(3);
var c = new cron.CronJob('* * * * * *', function() {
assert.ok(true);
});
var time = cron.time('*/2 * * * * *');
c.start();
setTimeout(function() {
c.stop();
c.setTime(time);
c.start();
setTimeout(function() {
c.stop();
assert.done();
}, 4250);
}, 1250);
},
'test start, change time, excpetion': function(assert) {
assert.expect(2);
var c = new cron.CronJob('* * * * * *', function() {
assert.ok(true);
});
var time = new Date();
c.start();
setTimeout(function() {
c.stop();
assert.throws(function() {
c.setTime(time);
});
assert.done();
}, 1250);
},
'test cronjob scoping': function(assert) {
assert.expect(2);
var c = new cron.CronJob('* * * * * *', function() {
assert.ok(true);
assert.ok(c instanceof cron.CronJob);
}, null, true);
setTimeout(function() {
c.stop();
assert.done();
}, 1250);
},
'test non-cronjob scoping': function(assert) {
assert.expect(2);
var c = new cron.CronJob('* * * * * *', function() {
assert.ok(true);
assert.equal(this.hello, 'world');
}, null, true, null, {'hello':'world'});
setTimeout(function() {
c.stop();
assert.done();
}, 1250);
},
'test non-cronjob scoping inside object': function(assert) {
assert.expect(2);
var c = new cron.CronJob({
cronTime: '* * * * * *',
onTick: function() {
assert.ok(true);
assert.equal(this.hello, 'world');
},
start: true,
context: {hello: 'world'}
});
setTimeout(function() {
c.stop();
assert.done();
}, 1250);
}
});
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