node-schedule
Advanced tools
Comparing version 0.1.16 to 0.2.0
@@ -16,3 +16,3 @@ /* | ||
var name; | ||
// process arguments to the constructor | ||
@@ -26,13 +26,13 @@ var arg; | ||
// else if (typeof(arg) == 'function') | ||
else | ||
else | ||
this.job = arg; | ||
} | ||
// give us a random name if one wasn't provided | ||
if (name == null) | ||
name = '<Anonymous Job ' + (++anonJobCounter) + '>'; | ||
// setup a private pendingInvocations variable | ||
var pendingInvocations = []; | ||
// define properties | ||
@@ -44,3 +44,3 @@ Object.defineProperty(this, 'name', { | ||
}); | ||
// method that require private access | ||
@@ -50,6 +50,6 @@ this.trackInvocation = function(invocation){ | ||
pendingInvocations.push(invocation); | ||
// and sort | ||
pendingInvocations.sort(sorter); | ||
return true; | ||
@@ -64,3 +64,3 @@ }; | ||
} | ||
return false; | ||
@@ -70,3 +70,3 @@ }; | ||
reschedule = (typeof(reschedule) == 'boolean') ? reschedule : false; | ||
var inv, newInv; | ||
@@ -77,5 +77,5 @@ var newInvs = []; | ||
inv = pendingInvocations[i]; | ||
cancelInvocation(inv); | ||
if (reschedule && inv.recurrenceRule.recurs) | ||
@@ -88,8 +88,8 @@ { | ||
} | ||
pendingInvocations = []; | ||
for (var i = 0; i < newInvs.length; i++) | ||
this.trackInvocation(newInvs[i]); | ||
return true; | ||
@@ -99,11 +99,11 @@ }; | ||
reschedule = (typeof(reschedule) == 'boolean') ? reschedule : true; | ||
if (pendingInvocations.length == 0) | ||
return false; | ||
var newInv; | ||
var nextInv = pendingInvocations.shift(); | ||
cancelInvocation(nextInv); | ||
if (reschedule && nextInv.recurrenceRule.recurs) | ||
@@ -115,3 +115,3 @@ { | ||
} | ||
return true; | ||
@@ -150,8 +150,12 @@ }; | ||
} else { | ||
spec = dateSpec(spec); | ||
if (typeof(spec) == 'object' && spec instanceof Date) { | ||
var type = typeof(spec); | ||
if (type === 'string') { | ||
spec = new Date(spec); | ||
} | ||
if (spec instanceof Date) { | ||
var inv = new Invocation(self, spec); | ||
scheduleInvocation(inv); | ||
success = self.trackInvocation(inv); | ||
} else if (typeof(spec) == 'object') { | ||
} else if (type === 'object') { | ||
if (!(spec instanceof RecurrenceRule)) { | ||
@@ -187,12 +191,2 @@ var r = new RecurrenceRule(); | ||
function dateSpec(spec) { | ||
if (spec instanceof Date === true) { | ||
var validDate = new Date(spec); | ||
if (validDate.toString() !== 'Invalid Date' && validDate > new Date()) { | ||
spec = validDate; | ||
} | ||
} | ||
return spec; | ||
} | ||
/* API | ||
@@ -215,3 +209,3 @@ invoke() | ||
this.recurrenceRule = recurrenceRule || DoesntRecur; | ||
this.timerID = null; | ||
@@ -241,3 +235,3 @@ } | ||
} | ||
return false; | ||
@@ -254,3 +248,3 @@ } | ||
array - value must validate against any item in list | ||
NOTE: Cron months are 1-based, but RecurrenceRule months are 0-based. | ||
@@ -260,3 +254,3 @@ */ | ||
this.recurs = true; | ||
this.year = (year == null) ? null : year; | ||
@@ -281,3 +275,3 @@ this.month = (month == null) ? null : month; | ||
return null; | ||
var now = new Date(); | ||
@@ -287,7 +281,7 @@ increment.addDateConvenienceMethods(now); | ||
return null; | ||
var next = new Date(base.getTime()); | ||
increment.addDateConvenienceMethods(next); | ||
next.addSecond(); | ||
while (true) | ||
@@ -348,6 +342,6 @@ { | ||
} | ||
break; | ||
} | ||
return next; | ||
@@ -359,3 +353,3 @@ }; | ||
return true; | ||
if (typeof(matcher) == 'number' || typeof(matcher) == 'string') | ||
@@ -365,3 +359,3 @@ return (val == matcher); | ||
return matcher.contains(val); | ||
else if (typeof(matcher) == 'array' || (typeof(matcher) == 'object' && matcher instanceof Array)) | ||
else if (Array.isArray(matcher) || (typeof(matcher) == 'object' && matcher instanceof Array)) | ||
{ | ||
@@ -375,3 +369,3 @@ for (var i = 0; i < matcher.length; i++) | ||
} | ||
return false; | ||
@@ -388,3 +382,3 @@ } | ||
var then = date.getTime(); | ||
if (then < now) | ||
@@ -418,5 +412,5 @@ { | ||
} | ||
currentInvocation = invocations[0]; | ||
var job = currentInvocation.job; | ||
@@ -426,3 +420,3 @@ var cinv = currentInvocation; | ||
currentInvocationFinished(); | ||
if (cinv.recurrenceRule.recurs || cinv.recurrenceRule._endDate === null) | ||
@@ -434,5 +428,5 @@ { | ||
} | ||
job.stopTrackingInvocation(cinv); | ||
job.invoke(); | ||
@@ -457,6 +451,6 @@ job.emit('run'); | ||
lt.clearTimeout(invocation.timerID); | ||
if (currentInvocation == invocation) | ||
currentInvocation = null; | ||
invocation.job.emit('canceled', invocation.fireDate); | ||
@@ -470,10 +464,10 @@ prepareNextInvocation(); | ||
prevDate = (prevDate instanceof Date) ? prevDate : (new Date()); | ||
var date = (rule instanceof RecurrenceRule) ? rule.nextInvocationDate(prevDate) : rule.next(); | ||
if (date === null) | ||
return null; | ||
var inv = new Invocation(job, date, rule); | ||
scheduleInvocation(inv); | ||
return inv; | ||
@@ -484,16 +478,18 @@ } | ||
var scheduledJobs = {}; | ||
function scheduleJob(){ | ||
if (arguments.length < 2) | ||
function scheduleJob() { | ||
if (arguments.length < 2) { | ||
return null; | ||
} | ||
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 job = new Job(name, method); | ||
if (job.schedule(spec)) | ||
{ | ||
if (job.schedule(spec)) { | ||
scheduledJobs[job.name] = job; | ||
return job; | ||
} | ||
return null; | ||
@@ -531,3 +527,3 @@ } | ||
} | ||
return success; | ||
@@ -545,2 +541,1 @@ } | ||
exports.addDateConvenienceMethods = increment.addDateConvenienceMethods; | ||
{ | ||
"name": "node-schedule", | ||
"version": "0.1.16", | ||
"version": "0.2.0", | ||
"description": "A cron-like and not-cron-like job scheduler for Node.", | ||
@@ -5,0 +5,0 @@ "keywords": ["schedule", "task", "job", "cron"], |
@@ -140,3 +140,3 @@ node-schedule | ||
This module was originally developed by [@mattpatt](https://github.com/mattpat) and is now maintained by [@tejasmanohar](https://github.com/tejasmanohar). | ||
This module was originally developed by [Matt Pat](https://github.com/mattpat), but is now maintained by [Tejas Manohar](https://github.com/tejasmanohar). | ||
@@ -143,0 +143,0 @@ That said, we have a lot of contributors that help this project stay alive! Find a bug? File an issue! Know how to fix? Submit a PR! |
@@ -76,3 +76,5 @@ var main = require('../package.json').main; | ||
var date = new Date(Date.now() + 3000); | ||
var job = new schedule.Job(); | ||
var job = new schedule.Job(function() { | ||
test.done(); | ||
}); | ||
@@ -84,6 +86,2 @@ job.on('scheduled', function(runAtDate) { | ||
job.schedule(date); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 3250); | ||
} | ||
@@ -90,0 +88,0 @@ }, |
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
45624
12
1171