New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-schedule

Package Overview
Dependencies
Maintainers
4
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-schedule - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

3

lib/increment.js

@@ -0,1 +1,2 @@

'use strict';

@@ -11,3 +12,3 @@

exports = module.exports.addDateConvenienceMethods = addDateConvenienceMethods;
module.exports.addDateConvenienceMethods = addDateConvenienceMethods;

@@ -14,0 +15,0 @@ function addDateConvenienceMethods(Date) {

@@ -0,1 +1,2 @@

'use strict';

@@ -17,27 +18,22 @@

function Job() {
var name;
function Job(name, job, callback) {
// setup a private pendingInvocations variable
var pendingInvocations = [];
// process arguments to the constructor
var arg;
for (var i = 0; i < arguments.length; i++) {
arg = arguments[i];
if (typeof arg == 'string' || arg instanceof String) {
name = arg;
} else {
this.job = arg;
}
}
// Set scope vars
var jobName = name && typeof name === 'string' ? name : '<Anonymous Job ' + (++anonJobCounter) + '>';
this.job = name && typeof name === 'function' ? name : job;
// give us a random name if one wasn't provided
if (name == null) {
name = '<Anonymous Job ' + (++anonJobCounter) + '>';
// Make sure callback is actually a callback
if (this.job === name) {
// Name wasn't provided and maybe a callback is there
this.callback = typeof job === 'function' ? job : false;
} else {
// Name was provided, and maybe a callback is there
this.callback = typeof callback === 'function' ? callback : false;
}
// setup a private pendingInvocations variable
var pendingInvocations = [];
// define properties
Object.defineProperty(this, 'name', {
value: name,
value: jobName,
writable: false,

@@ -158,3 +154,3 @@ enumerable: true

var type = typeof spec;
if (type === 'string') {
if ((type === 'string') || (type === 'number')) {
spec = new Date(spec);

@@ -202,2 +198,3 @@ }

scheduledJobs[this.name] = this;
return success;

@@ -394,2 +391,6 @@ };

if (job.callback) {
job.callback();
}
if (cinv.recurrenceRule.recurs || cinv.recurrenceRule._endDate === null) {

@@ -456,10 +457,10 @@ var inv = scheduleNextRecurrence(cinv.recurrenceRule, cinv.job, cinv.fireDate);

var name = (arguments.length >= 3) ? arguments[0] : null;
var spec = (arguments.length >= 3) ? arguments[1] : arguments[0];
var method = (arguments.length >= 3) ? arguments[2] : arguments[1];
var name = (arguments.length >= 3 && typeof arguments[0] === 'string') ? arguments[0] : null;
var spec = name ? arguments[1] : arguments[0];
var method = name ? arguments[2] : arguments[1];
var callback = name ? arguments[3] : arguments[2];
var job = new Job(name, method);
var job = new Job(name, method, callback);
if (job.schedule(spec)) {
scheduledJobs[job.name] = job;
return job;

@@ -485,9 +486,9 @@ }

/* Public API */
exports.Job = Job;
exports.Range = Range;
exports.RecurrenceRule = RecurrenceRule;
exports.Invocation = Invocation;
exports.scheduleJob = scheduleJob;
exports.scheduledJobs = scheduledJobs;
exports.cancelJob = cancelJob;
exports.addDateConvenienceMethods = increment.addDateConvenienceMethods;
module.exports.Job = Job;
module.exports.Range = Range;
module.exports.RecurrenceRule = RecurrenceRule;
module.exports.Invocation = Invocation;
module.exports.scheduleJob = scheduleJob;
module.exports.scheduledJobs = scheduledJobs;
module.exports.cancelJob = cancelJob;
module.exports.addDateConvenienceMethods = increment.addDateConvenienceMethods;
{
"name": "node-schedule",
"version": "0.2.9",
"version": "0.3.0",
"description": "A cron-like and not-cron-like job scheduler for Node.",

@@ -13,4 +13,4 @@ "keywords": [

"scripts": {
"test": "./node_modules/.bin/nodeunit test",
"lint": "./node_modules/.bin/eslint lib"
"test": "nodeunit && npm run lint",
"lint": "eslint lib"
},

@@ -24,3 +24,3 @@ "author": {

"type": "git",
"url": "https://github.com/tejasmanohar/node-schedule.git"
"url": "https://github.com/node-schedule/node-schedule.git"
},

@@ -27,0 +27,0 @@ "dependencies": {

# node-schedule
[![NPM version](http://img.shields.io/npm/v/node-schedule.svg)](https://www.npmjs.com/package/node-schedule) [![Downloads](https://img.shields.io/npm/dm/node-schedule.svg)](https://www.npmjs.com/package/node-schedule) [![Build Status](https://travis-ci.org/tejasmanohar/node-schedule.svg?branch=master)](https://travis-ci.org/tejasmanohar/node-schedule) [![Join the chat at https://gitter.im/tejasmanohar/node-schedule](https://img.shields.io/badge/gitter-chat-green.svg)](https://gitter.im/tejasmanohar/node-schedule?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![NPM version](http://img.shields.io/npm/v/node-schedule.svg)](https://www.npmjs.com/package/node-schedule) [![Downloads](https://img.shields.io/npm/dm/node-schedule.svg)](https://www.npmjs.com/package/node-schedule) [![Build Status](https://travis-ci.org/node-schedule/node-schedule.svg?branch=master)](https://travis-ci.org/node-schedule/node-schedule) [![Join the chat at https://gitter.im/node-schedule/node-schedule](https://img.shields.io/badge/gitter-chat-green.svg)](https://gitter.im/node-schedule/node-schedule?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![NPM](https://nodei.co/npm/node-schedule.png?downloads=true)](https://nodei.co/npm/node-schedule/)
>__Announcement:__ Node Schedule is looking for add additional collaborators with commit access. If you are actively involved in open source, ping [Tejas Manohar](http://tejas.io) (via [email](mailto:me@tejas.io), [Twitter](https://twitter.com/tejasmanohar), etc.) to express interest. Those who already contribute to the project are preferred.
node-schedule is a flexible cron-like and not-cron-like job scheduler for Node.js. It allows you to schedule jobs (arbitrary functions) for execution at specific dates, with optional recurrence rules. It only uses a single timer at any given time (rather than reevaluating upcoming jobs every second/minute).
Read more about the module's core functions on the [About](https://github.com/tejasmanohar/node-schedule/wiki/About) page of the wiki.
Read more about the module's core functions on the [About](https://github.com/node-schedule/node-schedule/wiki/About) page of the wiki.

@@ -22,3 +24,3 @@ ## Usage

Before jumping in, check out our [Contributing](https://github.com/tejasmanohar/node-schedule/wiki/Contributing) page on the wiki!
Before jumping in, check out our [Contributing](https://github.com/node-schedule/node-schedule/wiki/Contributing) page on the wiki!

@@ -34,7 +36,7 @@

[cron]: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
[wiki]: https://github.com/tejasmanohar/node-schedule/wiki
[contributing]: https://github.com/tejasmanohar/node-schedule/blob/master/CONTRIBUTING.md
[wiki]: https://github.com/node-schedule/node-schedule/wiki
[contributing]: https://github.com/node-schedule/node-schedule/blob/master/CONTRIBUTING.md
[Matt Patenaude]: https://github.com/mattpat
[license]: https://github.com/tejasmanohar/node-schedule/blob/master/LICENSE
[license]: https://github.com/node-schedule/node-schedule/blob/master/LICENSE
[Tejas Manohar]: https://github.com/tejasmanohar
[other wonderful contributors]: https://github.com/tejasmanohar/node-schedule/graphs/contributors
[other wonderful contributors]: https://github.com/node-schedule/node-schedule/graphs/contributors

@@ -0,1 +1,4 @@

'use strict';
var sinon = require('sinon');

@@ -170,2 +173,20 @@ var main = require('../package.json').main;

},
".scheduleJob({...}, {...}, fn)": {
"Callback called for each job if callback is provided": function(test) {
test.expect(3);
var job = new schedule.scheduleJob({
second: null // Fire every second
}, function() {}, function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
}
},
".cancelJob(Job)": {

@@ -172,0 +193,0 @@ "Prevents all future invocations of Job passed in": function(test) {

@@ -0,1 +1,4 @@

'use strict';
var sinon = require('sinon');

@@ -48,2 +51,17 @@ var main = require('../package.json').main;

},
"UTC": {
"Should accept a valid UTC date in milliseconds": function(test) {
test.expect(1);
schedule.scheduleJob(new Date(Date.now() + 1000).getTime(), function() {
test.ok(true);
});
setTimeout(function() {
test.done();
}, 1250);
clock.tick(1250);
}
},
tearDown: function(cb) {

@@ -50,0 +68,0 @@ clock.restore();

@@ -0,1 +1,4 @@

'use strict';
var sinon = require('sinon');

@@ -73,3 +76,3 @@ var main = require('../package.json').main;

job.runOnDate(new Date(Date.now() + 3000));
setTimeout(function() {

@@ -129,2 +132,19 @@ test.done();

},
"#schedule(Date, fn)": {
"Runs job once at some date, calls callback when done": function(test) {
test.expect(1);
var job = new schedule.Job(function() {}, function() {
test.ok(true);
});
job.schedule(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
}
},
"#schedule(RecurrenceRule)": {

@@ -251,2 +271,60 @@ "Runs job at interval based on recur rule, repeating indefinitely": function(test) {

},
"#schedule('jobName', {...})": {
"Runs job with a custom name input": function(test) {
test.expect(3);
var job = new schedule.Job('jobName', function() {
test.equal(job.name, 'jobName');
});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
}
},
"#schedule({...}, {...})": {
"Runs job and run callback when job is done if callback is provided": function(test) {
test.expect(3);
var job = new schedule.Job(function() {}, function() {
test.ok(true);
});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Runs job with a custom name input and run callback when job is done": function(test) {
test.expect(3);
var job = new schedule.Job('MyJob', function() {}, function() {
test.equal(job.name, 'MyJob');
});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
}
},
"#cancel": {

@@ -297,14 +375,22 @@ "Prevents all future invocations": function(test) {

},
"Job is removed from scheduledJobs": function(test) {
test.expect(1);
"Job is added to scheduledJobs when created and removed when cancelled": function(test) {
test.expect(4);
var job = new schedule.Job('cancelJob', function() {});
job.schedule({
var job1 = new schedule.Job('cancelJob', function() {});
job1.schedule({
second: null // fire every second
});
var job2 = schedule.scheduleJob('second',
{ second: null },
function() {},
function() {});
test.equal(schedule.scheduledJobs.cancelJob, job1);
test.equal(schedule.scheduledJobs.second, job2);
setTimeout(function() {
job.cancel();
job1.cancel();
job2.cancel();
test.equal(schedule.scheduledJobs.cancelJob, null);
test.equal(schedule.scheduledJobs.second, null);
test.done();

@@ -311,0 +397,0 @@ }, 1250);

@@ -0,1 +1,4 @@

'use strict';
var main = require('../package.json').main;

@@ -2,0 +5,0 @@ var schedule = require('../' + main);

@@ -0,1 +1,4 @@

'use strict';
var main = require('../package.json').main;

@@ -2,0 +5,0 @@ var schedule = require('../' + main);

@@ -0,1 +1,4 @@

'use strict';
var sinon = require('sinon');

@@ -2,0 +5,0 @@ var main = require('../package.json').main;

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