node-schedule
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -32,3 +32,5 @@ 'use strict'; | ||
// give us a random name if one wasn't provided | ||
if (name == null) name = '<Anonymous Job ' + (++anonJobCounter) + '>'; | ||
if (name == null) { | ||
name = '<Anonymous Job ' + (++anonJobCounter) + '>'; | ||
} | ||
@@ -76,3 +78,5 @@ // setup a private pendingInvocations variable | ||
newInv = scheduleNextRecurrence(inv.recurrenceRule, this, inv.fireDate); | ||
if (newInv !== null) newInvs.push(newInv); | ||
if (newInv !== null) { | ||
newInvs.push(newInv); | ||
} | ||
} | ||
@@ -87,2 +91,9 @@ } | ||
// remove from scheduledJobs if reschedule === false | ||
if (!reschedule) { | ||
if (this.name) { | ||
scheduledJobs[this.name] = null; | ||
} | ||
} | ||
return true; | ||
@@ -93,3 +104,5 @@ }; | ||
if (!pendingInvocations.length) return false; | ||
if (!pendingInvocations.length) { | ||
return false; | ||
} | ||
@@ -103,3 +116,5 @@ var newInv; | ||
newInv = scheduleNextRecurrence(nextInv.recurrenceRule, this, nextInv.fireDate); | ||
if (newInv !== null) this.trackInvocation(newInv); | ||
if (newInv !== null) { | ||
this.trackInvocation(newInv); | ||
} | ||
} | ||
@@ -110,3 +125,5 @@ | ||
this.nextInvocation = function() { | ||
if (!pendingInvocations.length) return null; | ||
if (!pendingInvocations.length) { | ||
return null; | ||
} | ||
return pendingInvocations[0].fireDate; | ||
@@ -140,21 +157,42 @@ }; | ||
inv = scheduleNextRecurrence(res, self); | ||
if (inv !== null) success = self.trackInvocation(inv); | ||
if (inv !== null) { | ||
success = self.trackInvocation(inv); | ||
} | ||
} catch (err) { | ||
var type = typeof spec; | ||
if (type === 'string') spec = new Date(spec); | ||
if (type === 'string') { | ||
spec = new Date(spec); | ||
} | ||
if (spec instanceof Date) { | ||
inv = new Invocation(self, spec); | ||
scheduleInvocation(inv); | ||
success = self.trackInvocation(inv); | ||
if (spec.getTime() >= Date.now()) { | ||
inv = new Invocation(self, spec); | ||
scheduleInvocation(inv); | ||
success = self.trackInvocation(inv); | ||
} | ||
} else if (type === 'object') { | ||
if (!(spec instanceof RecurrenceRule)) { | ||
var r = new RecurrenceRule(); | ||
if ('year' in spec) r.year = spec.year; | ||
if ('month' in spec) r.month = spec.month; | ||
if ('date' in spec) r.date = spec.date; | ||
if ('dayOfWeek' in spec) r.dayOfWeek = spec.dayOfWeek; | ||
if ('hour' in spec) r.hour = spec.hour; | ||
if ('minute' in spec) r.minute = spec.minute; | ||
if ('second' in spec) r.second = spec.second; | ||
if ('year' in spec) { | ||
r.year = spec.year; | ||
} | ||
if ('month' in spec) { | ||
r.month = spec.month; | ||
} | ||
if ('date' in spec) { | ||
r.date = spec.date; | ||
} | ||
if ('dayOfWeek' in spec) { | ||
r.dayOfWeek = spec.dayOfWeek; | ||
} | ||
if ('hour' in spec) { | ||
r.hour = spec.hour; | ||
} | ||
if ('minute' in spec) { | ||
r.minute = spec.minute; | ||
} | ||
if ('second' in spec) { | ||
r.second = spec.second; | ||
} | ||
@@ -165,3 +203,5 @@ spec = r; | ||
inv = scheduleNextRecurrence(spec, self); | ||
if (inv !== null) success = self.trackInvocation(inv); | ||
if (inv !== null) { | ||
success = self.trackInvocation(inv); | ||
} | ||
} | ||
@@ -214,3 +254,5 @@ } | ||
for (var i = this.start; i < this.end; i += this.step) { | ||
if (i === val) return true; | ||
if (i === val) { | ||
return true; | ||
} | ||
} | ||
@@ -244,15 +286,14 @@ | ||
RecurrenceRule.prototype.validate = function() { | ||
// TODO: validation | ||
return true; | ||
}; | ||
RecurrenceRule.prototype.nextInvocationDate = function(base) { | ||
base = (base instanceof Date) ? base : (new Date()); | ||
increment.addDateConvenienceMethods(base); | ||
if (!this.recurs) return null; | ||
if (!this.recurs) { | ||
return null; | ||
} | ||
var now = new Date(); | ||
increment.addDateConvenienceMethods(now); | ||
if (this.year !== null && (typeof this.year == 'number') && this.year < now.getFullYear()) return null; | ||
if (this.year !== null && (typeof this.year == 'number') && this.year < now.getFullYear()) { | ||
return null; | ||
} | ||
@@ -318,13 +359,16 @@ var next = new Date(base.getTime()); | ||
function recurMatch(val, matcher) { | ||
if (matcher == null) return true; | ||
if (matcher == null) { | ||
return true; | ||
} | ||
if (typeof matcher === 'number' || typeof matcher === 'string') { | ||
return (val === matcher); | ||
} else if (typeof matcher === 'object' && matcher instanceof Range) { | ||
} else if (matcher instanceof Range) { | ||
return matcher.contains(val); | ||
} else if (Array.isArray(matcher) || (typeof matcher === 'object' && matcher instanceof Array)) { | ||
} else if (Array.isArray(matcher) || (matcher instanceof Array)) { | ||
for (var i = 0; i < matcher.length; i++) { | ||
if (recurMatch(val, matcher[i])) return true; | ||
if (recurMatch(val, matcher[i])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
@@ -375,3 +419,5 @@ | ||
var inv = scheduleNextRecurrence(cinv.recurrenceRule, cinv.job, cinv.fireDate); | ||
if (inv !== null) inv.job.trackInvocation(inv); | ||
if (inv !== null) { | ||
inv.job.trackInvocation(inv); | ||
} | ||
} | ||
@@ -397,5 +443,9 @@ | ||
invocations.splice(idx, 1); | ||
if (invocation.timerID !== null) lt.clearTimeout(invocation.timerID); | ||
if (invocation.timerID !== null) { | ||
lt.clearTimeout(invocation.timerID); | ||
} | ||
if (currentInvocation === invocation) currentInvocation = null; | ||
if (currentInvocation === invocation) { | ||
currentInvocation = null; | ||
} | ||
@@ -412,3 +462,5 @@ invocation.job.emit('canceled', invocation.fireDate); | ||
var date = (rule instanceof RecurrenceRule) ? rule.nextInvocationDate(prevDate) : rule.next(); | ||
if (date === null) return null; | ||
if (date === null) { | ||
return null; | ||
} | ||
@@ -425,3 +477,5 @@ var inv = new Invocation(job, date, rule); | ||
function scheduleJob() { | ||
if (arguments.length < 2) return null; | ||
if (arguments.length < 2) { | ||
return null; | ||
} | ||
@@ -446,16 +500,5 @@ var name = (arguments.length >= 3) ? arguments[0] : null; | ||
success = job.cancel(); | ||
if (success) { | ||
for (var name in scheduledJobs) { | ||
if (scheduledJobs.hasOwnProperty(name)) { | ||
if (scheduledJobs[name] === job) { | ||
scheduledJobs[name] = null; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} else if (typeof job == 'string' || job instanceof String) { | ||
if (job in scheduledJobs && scheduledJobs.hasOwnProperty(job)) { | ||
success = scheduledJobs[job].cancel(); | ||
if (success) scheduledJobs[job] = null; | ||
} | ||
@@ -462,0 +505,0 @@ } |
{ | ||
"name": "node-schedule", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "A cron-like and not-cron-like job scheduler for Node.", | ||
"keywords": ["schedule", "task", "job", "cron"], | ||
"keywords": [ | ||
"schedule", | ||
"task", | ||
"job", | ||
"cron" | ||
], | ||
"main": "./lib/schedule.js", | ||
@@ -21,10 +26,12 @@ "scripts": { | ||
"dependencies": { | ||
"cron-parser": "0.6.1", | ||
"long-timeout": "0.0.1" | ||
"cron-parser": "0.6.2", | ||
"long-timeout": "0.0.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "0.15.1", | ||
"nodeunit": "0.9.1", | ||
"sinon": "1.12.2" | ||
"coveralls": "^2.11.2", | ||
"eslint": "^0.15.1", | ||
"istanbul": "^0.3.8", | ||
"nodeunit": "^0.9.1", | ||
"sinon": "^1.14.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# 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/node-schedule/node-schedule.svg?branch=master)](https://travis-ci.org/node-schedule/node-schedule) | ||
# 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) [![Coverage Status](https://coveralls.io/repos/node-schedule/node-schedule/badge.svg?branch=master)](https://coveralls.io/r/node-schedule/node-schedule?branch=master) [![Build Status](https://travis-ci.org/node-schedule/node-schedule.svg?branch=master)](https://travis-ci.org/node-schedule/node-schedule) | ||
@@ -7,3 +7,3 @@ [![NPM](https://nodei.co/npm/node-schedule.png?downloads=true)](https://nodei.co/npm/node-schedule/) | ||
Read more about the module's core functions on the [About](https://github.com/mattpat/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. | ||
@@ -17,28 +17,12 @@ ## Usage | ||
We're committed to a loosely-coupled architecture for node-schedule and would love to get your contributions. | ||
This module was originally developed by [Matt Patenaude], and is now maintained by [Tejas Manohar] and [other wonderful contributors]. | ||
Before jumping in, check out our [Contributing](https://github.com/mattpat/node-schedule/wiki/Contributing) page on the wiki! | ||
We'd love to get your contributions. Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. | ||
Before jumping in, check out our [Contributing](https://github.com/node-schedule/node-schedule/wiki/Contributing) page on the wiki! | ||
## Core Team | ||
This module was originally developed by [Matt Patenaude], but the new team is as follows: | ||
**Tejas Manohar - Maintainer** | ||
- <https://twitter.com/tejasmanohar> | ||
- <https://github.com/tejasmanohar> | ||
**Santiago Gimeno - Collaborator** | ||
- <https://github.com/santigimeno> | ||
**Jon Hester - Collaborator** | ||
- <https://github.com/jonhester> | ||
## Copyright and license | ||
node-schedule is copyright 2011-2015 Matt Patenaude. | ||
Copyright 2015 Matt Patenaude. | ||
@@ -53,1 +37,3 @@ Licensed under the **[MIT License] [license]**. | ||
[license]: https://github.com/mattpat/node-schedule/blob/master/LICENSE | ||
[Tejas Manohar]: https://github.com/tejasmanohar | ||
[other wonderful contributors]: https://github.com/node-schedule/node-schedule/graphs/contributors |
@@ -48,13 +48,17 @@ var sinon = require('sinon'); | ||
clock.tick(1250); | ||
} | ||
/*, | ||
"Won't run job if scheduled in the past": function(test) { | ||
schedule.scheduleJob(new Date(Date.now() - 3000), function() { | ||
}, | ||
"Won't run job if scheduled in the past": function(test) { | ||
test.expect(1); | ||
var job = schedule.scheduleJob(new Date(Date.now() - 3000), function() { | ||
test.ok(false); | ||
}); | ||
}); | ||
setTimeout(function() { | ||
test.equal(job, null); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
}*/ | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -100,17 +104,20 @@ ".scheduleJob(RecurrenceRule, fn)": { | ||
clock.tick(3250); | ||
} | ||
/*, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 2000; | ||
}, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(1); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 1960; | ||
var job = schedule.scheduleJob(rule, function() { | ||
var job = schedule.scheduleJob(rule, function() { | ||
test.ok(false); | ||
}); | ||
}); | ||
test.equal(job, null); | ||
setTimeout(function() { | ||
job.cancel(); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
}*/ | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -157,16 +164,20 @@ ".scheduleJob({...}, fn)": { | ||
clock.tick(2250); | ||
} | ||
/*, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
var job = new schedule.scheduleJob({ | ||
year: 2000 | ||
}, function() { | ||
}, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(1); | ||
var job = schedule.scheduleJob({ | ||
year: 1960 | ||
}, function() { | ||
test.ok(false); | ||
}); | ||
}); | ||
test.equal(job, null); | ||
setTimeout(function() { | ||
job.cancel(); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
}*/ | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -173,0 +184,0 @@ ".cancelJob(Job)": { |
@@ -73,3 +73,3 @@ var sinon = require('sinon'); | ||
job.runOnDate(new Date(Date.now() + 3000)); | ||
setTimeout(function() { | ||
@@ -81,3 +81,2 @@ test.done(); | ||
}, | ||
/* No jobs will run after this test for some reason - hide for now | ||
"Won't run job if scheduled in the past": function(test) { | ||
@@ -87,3 +86,3 @@ test.expect(0); | ||
var job = new schedule.Job(function() { | ||
test.ok(true); | ||
test.ok(false); | ||
}); | ||
@@ -94,4 +93,6 @@ | ||
setTimeout(function() { | ||
test.done(); | ||
test.done(); | ||
}, 1000); | ||
clock.tick(1000); | ||
}, | ||
@@ -103,15 +104,19 @@ "Jobs still run after scheduling a Job in the past": function(test) { | ||
// Should not run, blow up if it does | ||
test.ok(false); | ||
test.ok(false); | ||
}); | ||
pastJob.schedule(new Date(Date.now() - 3000)); | ||
var job = new schedule.Job(function() { | ||
test.ok(true); | ||
test.ok(true); | ||
}); | ||
job.schedule(new Date(Date.now() + 3000)); | ||
setTimeout(function() { | ||
test.done(); | ||
test.done(); | ||
}, 3250); | ||
},*/ | ||
clock.tick(3250); | ||
}, | ||
"Job emits 'scheduled' event with 'run at' Date": function(test) { | ||
@@ -175,21 +180,22 @@ test.expect(1); | ||
clock.tick(3250); | ||
} | ||
/*, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(0); | ||
}, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(0); | ||
var job = new schedule.Job(function() { | ||
var job = new schedule.Job(function() { | ||
test.ok(false); | ||
}); | ||
}); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 2000; | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 2000; | ||
job.schedule(rule); | ||
job.schedule(rule); | ||
setTimeout(function() { | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 1000); | ||
}*/ | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -236,20 +242,21 @@ "#schedule({...})": { | ||
clock.tick(3250); | ||
} | ||
/*, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(0); | ||
}, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(0); | ||
var job = new schedule.Job(function() { | ||
var job = new schedule.Job(function() { | ||
test.ok(false); | ||
}); | ||
}); | ||
job.schedule({ | ||
job.schedule({ | ||
year: 2000 | ||
}); | ||
}); | ||
setTimeout(function() { | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 1000); | ||
}*/ | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -300,2 +307,19 @@ "#cancel": { | ||
clock.tick(2250); | ||
}, | ||
"Job is removed from scheduledJobs": function(test) { | ||
test.expect(1); | ||
var job = new schedule.Job('cancelJob', function() {}); | ||
job.schedule({ | ||
second: null // fire every second | ||
}); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.equal(schedule.scheduledJobs.cancelJob, null); | ||
test.done(); | ||
}, 1250); | ||
clock.tick(1250); | ||
} | ||
@@ -302,0 +326,0 @@ }, |
@@ -239,4 +239,23 @@ var main = require('../package.json').main; | ||
test.done(); | ||
}, | ||
"From 31th May schedule the 1st of every June": function(test) { | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.second = 0; | ||
rule.minute = 0; | ||
rule.hour = 0; | ||
rule.date = 1; | ||
rule.month = 5; | ||
var next; | ||
var base1 = new Date(2010, 4, 31, 12, 30, 15, 0); | ||
next = rule.nextInvocationDate(base1); | ||
test.deepEqual(new Date(2010, 5, 1, 0, 0, 0, 0), next); | ||
next = rule.nextInvocationDate(next); | ||
test.deepEqual(new Date(2011, 5, 1, 0, 0, 0, 0), next); | ||
test.done(); | ||
} | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46444
1389
5
37
+ Addedcron-parser@0.6.2(transitive)
+ Addedlong-timeout@0.0.2(transitive)
- Removedcron-parser@0.6.1(transitive)
- Removedlong-timeout@0.0.1(transitive)
Updatedcron-parser@0.6.2
Updatedlong-timeout@0.0.2