This commit is contained in:
你的名字
2025-07-14 10:22:40 +08:00
commit 0483b4b364
1388 changed files with 219353 additions and 0 deletions

17
nodejs/node_modules/node-schedule/.eslintrc generated vendored Executable file
View File

@ -0,0 +1,17 @@
{
"env": {
"node": true,
"es6": true
},
"rules": {
"eqeqeq": ["error", "smart"],
"indent": ["error", 2, { "SwitchCase": 1 }],
"no-constant-condition": "off",
"no-redeclare": "warn",
"no-underscore-dangle": "off",
"no-use-before-define": ["warn","nofunc"],
"quotes": ["error", "single"],
"space-before-blocks": "error",
"strict": "error"
}
}

15
nodejs/node_modules/node-schedule/.travis.yml generated vendored Executable file
View File

@ -0,0 +1,15 @@
language: node_js
node_js:
- "0.12"
- "0.10"
- "4"
- "6"
- "7"
before_script: >
if nvm ls-remote --lts | grep "$(nvm current)"; then
echo "running on a LTS node version, linting"
npm test
else
echo "running on a non-LTS node version, skipping linting"
fi
script: ./node_modules/.bin/istanbul cover ./node_modules/.bin/nodeunit test && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage

31
nodejs/node_modules/node-schedule/CONTRIBUTING.md generated vendored Executable file
View File

@ -0,0 +1,31 @@
## Rules
1. **No `--force` pushes** or modifying the git history in any way
2. Follow existing code style
3. Pull requests with tests are much more likely to be accepted
4. Follow the guidelines below
## Bugfix or Feature?
This project uses the [gitflow workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow). Simply put, you need to decide if your contribution will be a bug fix that could be released as a patch, or a feature that will end up being a minor or major release.
### Found a bug that can be fixed without affecting the API?
1. **Fork** this repo
2. Create a new branch from `master` to work in
3. **Add tests** if needed
4. Make sure your code **lints** by running `npm run lint`
5. Make sure your code **passes tests** by running `npm test`
6. Submit a **pull request** against the `master` branch
### New feature or anything that would result in a change to the API?
1. **Fork** this repo
2. Create a new branch from `develop` to work in
3. **Add tests** to as needed
4. Make sure your code **lints** by running `npm run lint`
5. Make sure your code **passes tests** by running `npm test`
6. Submit a **pull request** against the `develop` branch
## Releases
Declaring formal releases remains the prerogative of the project maintainer.

19
nodejs/node_modules/node-schedule/LICENSE generated vendored Executable file
View File

@ -0,0 +1,19 @@
Copyright (C) 2015 Matt Patenaude.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

256
nodejs/node_modules/node-schedule/README.md generated vendored Executable file
View File

@ -0,0 +1,256 @@
# 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)
[![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/)
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).
## Usage
### Installation
You can install using [npm](https://www.npmjs.com/package/node-schedule).
```
npm install node-schedule
```
### Overview
Node Schedule is for time-based scheduling, not interval-based scheduling.
While you can easily bend it to your will, if you only want to do something like
"run this function every 5 minutes", you'll find `setInterval` much easier to use,
and far more appropriate. But if you want to, say, "run this function at the :20
and :50 of every hour on the third Tuesday of every month," you'll find that
Node Schedule suits your needs better. Additionally, Node Schedule has Windows
support unlike true cron since the node runtime is now fully supported.
Note that Node Schedule is designed for in-process scheduling, i.e. scheduled jobs
will only fire as long as your script is running, and the schedule will disappear
when execution completes. If you need to schedule jobs that will persist even when
your script *isn't* running, consider using actual [cron].
### Jobs and Scheduling
Every scheduled job in Node Schedule is represented by a `Job` object. You can
create jobs manually, then execute the `schedule()` method to apply a schedule,
or use the convenience function `scheduleJob()` as demonstrated below.
`Job` objects are `EventEmitter`'s, and emit a `run` event after each execution.
They also emit a `scheduled` event each time they're scheduled to run, and a
`canceled` event when an invocation is canceled before it's executed (both events
receive a JavaScript date object as a parameter). Note that jobs are scheduled the
first time immediately, so if you create a job using the `scheduleJob()`
convenience method, you'll miss the first `scheduled` event, but you can query the
invocation manually (see below). Also note that `canceled` is the single-L American
spelling.
### Cron-style Scheduling
The cron format consists of:
```
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
```
Examples with the cron format:
```js
var schedule = require('node-schedule');
var j = schedule.scheduleJob('42 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
```
Execute a cron job when the minute is 42 (e.g. 19:42, 20:42, etc.).
And:
```js
var j = schedule.scheduleJob('0 17 ? * 0,4-6', function(){
console.log('Today is recognized by Rebecca Black!');
});
```
Execute a cron job every 5 Minutes = */5 * * * *
You can also get when it is scheduled to run for every invocation of the job:
```js
var j = schedule.scheduleJob('0 1 * * *', function(fireDate){
console.log('This job was supposed to run at ' + fireDate + ', but actually ran at ' + new Date());
});
```
This is useful when you need to check if there is a delay of the job invocation when the system is busy, or save a record of all invocations of a job for audit purpose.
#### Unsupported Cron Features
Currently, `W` (nearest weekday), `L` (last day of month/week), and `#` (nth weekday
of the month) are not supported. Most other features supported by popular cron
implementations should work just fine.
[cron-parser] is used to parse crontab instructions.
### Date-based Scheduling
Say you very specifically want a function to execute at 5:30am on December 21, 2012.
Remember - in JavaScript - 0 - January, 11 - December.
```js
var schedule = require('node-schedule');
var date = new Date(2012, 11, 21, 5, 30, 0);
var j = schedule.scheduleJob(date, function(){
console.log('The world is going to end today.');
});
```
To use current data in the future you can use binding:
```js
var schedule = require('node-schedule');
var date = new Date(2012, 11, 21, 5, 30, 0);
var x = 'Tada!';
var j = schedule.scheduleJob(date, function(y){
console.log(y);
}.bind(null,x));
x = 'Changing Data';
```
This will log 'Tada!' when the scheduled Job runs, rather than 'Changing Data',
which x changes to immediately after scheduling.
### Recurrence Rule Scheduling
You can build recurrence rules to specify when a job should recur. For instance,
consider this rule, which executes the function every hour at 42 minutes after the hour:
```js
var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
rule.minute = 42;
var j = schedule.scheduleJob(rule, function(){
console.log('The answer to life, the universe, and everything!');
});
```
You can also use arrays to specify a list of acceptable values, and the `Range`
object to specify a range of start and end values, with an optional step parameter.
For instance, this will print a message on Thursday, Friday, Saturday, and Sunday at 5pm:
```js
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [0, new schedule.Range(4, 6)];
rule.hour = 17;
rule.minute = 0;
var j = schedule.scheduleJob(rule, function(){
console.log('Today is recognized by Rebecca Black!');
});
```
#### RecurrenceRule properties
- `second`
- `minute`
- `hour`
- `date`
- `month`
- `year`
- `dayOfWeek`
> **Note**: It's worth noting that the default value of a component of a recurrence rule is
> `null` (except for second, which is 0 for familiarity with cron). *If we did not
> explicitly set `minute` to 0 above, the message would have instead been logged at
> 5:00pm, 5:01pm, 5:02pm, ..., 5:59pm.* Probably not what you want.
#### Object Literal Syntax
To make things a little easier, an object literal syntax is also supported, like
in this example which will log a message every Sunday at 2:30pm:
```js
var j = schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 0}, function(){
console.log('Time for tea!');
});
```
#### Set StartTime and EndTime
It will run after 5 seconds and stop after 10 seconds in this example.
The ruledat supports the above.
```js
let startTime = new Date(Date.now() + 5000);
let endTime = new Date(startTime.getTime() + 5000);
var j = schedule.scheduleJob({ start: startTime, end: endTime, rule: '*/1 * * * * *' }, function(){
console.log('Time for tea!');
});
```
### Handle Jobs and Job Invocations
There are some function to get informations for a Job and to handle the Job and
Invocations.
#### job.cancel(reshedule)
You can invalidate any job with the `cancel()` method:
```js
j.cancel();
```
All planned invocations will be canceled. When you set the parameter ***reschedule***
to true then the Job is newly scheduled afterwards.
#### job.cancelNext(reshedule)
This method invalidates the next planned invocation or the job.
When you set the parameter ***reschedule*** to true then the Job is newly scheduled
afterwards.
#### job.reschedule(spec)
This method cancels all pending invocation and registers the Job completely new again using the given specification.
Return true/false on success/failure.
#### job.nextInvocation()
This method returns a Date object for the planned next Invocation for this Job. If no invocation is planned the method returns null.
## Contributing
This module was originally developed by [Matt Patenaude], and is now maintained by
[Tejas Manohar] and [other wonderful contributors].
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] page guide!
## Copyright and license
Copyright 2015 Matt Patenaude.
Licensed under the **[MIT License] [license]**.
[cron]: http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
[Contributing]: https://github.com/node-schedule/node-schedule/blob/master/CONTRIBUTING.md
[Matt Patenaude]: https://github.com/mattpat
[Tejas Manohar]: http://tejas.io
[license]: https://github.com/node-schedule/node-schedule/blob/master/LICENSE
[Tejas Manohar]: https://github.com/tejasmanohar
[other wonderful contributors]: https://github.com/node-schedule/node-schedule/graphs/contributors
[cron-parser]: https://github.com/harrisiirak/cron-parser

648
nodejs/node_modules/node-schedule/lib/schedule.js generated vendored Executable file
View File

@ -0,0 +1,648 @@
'use strict';
/*
node-schedule
A cron-like and not-cron-like job scheduler for Node.
*/
var events = require('events'),
util = require('util'),
cronParser = require('cron-parser'),
CronDate = require('cron-parser/lib/date'),
lt = require('long-timeout'),
sorted = require('sorted-array-functions');
/* Job object */
var anonJobCounter = 0;
var scheduledJobs = {};
function isValidDate(date) {
// Taken from http://stackoverflow.com/a/12372720/1562178
// If getTime() returns NaN it'll return false anyway
return date.getTime() === date.getTime();
}
function Job(name, job, callback) {
// setup a private pendingInvocations variable
var pendingInvocations = [];
//setup a private number of invocations variable
var triggeredJobs = 0;
// Set scope vars
var jobName = name && typeof name === 'string' ? name : '<Anonymous Job ' + (++anonJobCounter) + '>';
this.job = name && typeof name === 'function' ? name : job;
// 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;
}
// Check for generator
if (typeof this.job === 'function' &&
this.job.prototype &&
this.job.prototype.next) {
this.job = function() {
return this.next().value;
}.bind(this.job.call(this));
}
// define properties
Object.defineProperty(this, 'name', {
value: jobName,
writable: false,
enumerable: true
});
// method that require private access
this.trackInvocation = function(invocation) {
// add to our invocation list
sorted.add(pendingInvocations, invocation, sorter);
return true;
};
this.stopTrackingInvocation = function(invocation) {
var invIdx = pendingInvocations.indexOf(invocation);
if (invIdx > -1) {
pendingInvocations.splice(invIdx, 1);
return true;
}
return false;
};
this.triggeredJobs = function() {
return triggeredJobs;
};
this.setTriggeredJobs = function(triggeredJob) {
triggeredJobs = triggeredJob;
};
this.cancel = function(reschedule) {
reschedule = (typeof reschedule == 'boolean') ? reschedule : false;
var inv, newInv;
var newInvs = [];
for (var j = 0; j < pendingInvocations.length; j++) {
inv = pendingInvocations[j];
cancelInvocation(inv);
if (reschedule && inv.recurrenceRule.recurs) {
newInv = scheduleNextRecurrence(inv.recurrenceRule, this, inv.fireDate, inv.endDate);
if (newInv !== null) {
newInvs.push(newInv);
}
}
}
pendingInvocations = [];
for (var k = 0; k < newInvs.length; k++) {
this.trackInvocation(newInvs[k]);
}
// remove from scheduledJobs if reschedule === false
if (!reschedule) {
if (this.name) {
delete scheduledJobs[this.name];
}
}
return true;
};
this.cancelNext = function(reschedule) {
reschedule = (typeof reschedule == 'boolean') ? reschedule : true;
if (!pendingInvocations.length) {
return false;
}
var newInv;
var nextInv = pendingInvocations.shift();
cancelInvocation(nextInv);
if (reschedule && nextInv.recurrenceRule.recurs) {
newInv = scheduleNextRecurrence(nextInv.recurrenceRule, this, nextInv.fireDate, nextInv.endDate);
if (newInv !== null) {
this.trackInvocation(newInv);
}
}
return true;
};
this.reschedule = function(spec) {
var inv;
var cInvs = pendingInvocations.slice();
for (var j = 0; j < cInvs.length; j++) {
inv = cInvs[j];
cancelInvocation(inv);
}
pendingInvocations = [];
if (this.schedule(spec)) {
this.setTriggeredJobs(0);
return true;
} else {
pendingInvocations = cInvs;
return false;
}
};
this.nextInvocation = function() {
if (!pendingInvocations.length) {
return null;
}
return pendingInvocations[0].fireDate;
};
this.pendingInvocations = function() {
return pendingInvocations;
};
}
util.inherits(Job, events.EventEmitter);
Job.prototype.invoke = function(fireDate) {
if (typeof this.job == 'function') {
this.setTriggeredJobs(this.triggeredJobs() + 1);
this.job(fireDate);
} else {
this.job.execute(fireDate);
}
};
Job.prototype.runOnDate = function(date) {
return this.schedule(date);
};
Job.prototype.schedule = function(spec) {
var self = this;
var success = false;
var inv;
var start;
var end;
var tz;
if (typeof spec === 'object' && spec.rule) {
start = spec.start || undefined;
end = spec.end || undefined;
tz = spec.tz;
spec = spec.rule;
if (start) {
if (!(start instanceof Date)) {
start = new Date(start);
}
start = new CronDate(start, tz);
if (!isValidDate(start) || start.getTime() < Date.now()) {
start = undefined;
}
}
if (end && !(end instanceof Date) && !isValidDate(end = new Date(end))) {
end = undefined;
}
if (end) {
end = new CronDate(end, tz);
}
}
try {
var res = cronParser.parseExpression(spec, { currentDate: start, tz: tz });
inv = scheduleNextRecurrence(res, self, start, end);
if (inv !== null) {
success = self.trackInvocation(inv);
}
} catch (err) {
var type = typeof spec;
if ((type === 'string') || (type === 'number')) {
spec = new Date(spec);
}
if ((spec instanceof Date) && (isValidDate(spec))) {
spec = new CronDate(spec);
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;
}
spec = r;
}
spec.tz = tz;
inv = scheduleNextRecurrence(spec, self, start, end);
if (inv !== null) {
success = self.trackInvocation(inv);
}
}
}
scheduledJobs[this.name] = this;
return success;
};
/* API
invoke()
runOnDate(date)
schedule(date || recurrenceRule || cronstring)
cancel(reschedule = false)
cancelNext(reschedule = true)
Property constraints
name: readonly
job: readwrite
*/
/* DoesntRecur rule */
var DoesntRecur = new RecurrenceRule();
DoesntRecur.recurs = false;
/* Invocation object */
function Invocation(job, fireDate, recurrenceRule, endDate) {
this.job = job;
this.fireDate = fireDate;
this.endDate = endDate;
this.recurrenceRule = recurrenceRule || DoesntRecur;
this.timerID = null;
}
function sorter(a, b) {
return (a.fireDate.getTime() - b.fireDate.getTime());
}
/* Range object */
function Range(start, end, step) {
this.start = start || 0;
this.end = end || 60;
this.step = step || 1;
}
Range.prototype.contains = function(val) {
if (this.step === null || this.step === 1) {
return (val >= this.start && val <= this.end);
} else {
for (var i = this.start; i < this.end; i += this.step) {
if (i === val) {
return true;
}
}
return false;
}
};
/* RecurrenceRule object */
/*
Interpreting each property:
null - any value is valid
number - fixed value
Range - value must fall in range
array - value must validate against any item in list
NOTE: Cron months are 1-based, but RecurrenceRule months are 0-based.
*/
function RecurrenceRule(year, month, date, dayOfWeek, hour, minute, second) {
this.recurs = true;
this.year = (year == null) ? null : year;
this.month = (month == null) ? null : month;
this.date = (date == null) ? null : date;
this.dayOfWeek = (dayOfWeek == null) ? null : dayOfWeek;
this.hour = (hour == null) ? null : hour;
this.minute = (minute == null) ? null : minute;
this.second = (second == null) ? 0 : second;
}
RecurrenceRule.prototype.isValid = function() {
function isValidType(num) {
if (Array.isArray(num) || (num instanceof Array)) {
return num.every(function(e) {
return isValidType(e);
});
}
return !(Number.isNaN(Number(num)) && !(num instanceof Range));
}
if (this.month !== null && (this.month < 0 || this.month > 11 || !isValidType(this.month))) {
return false;
}
if (this.dayOfWeek !== null && (this.dayOfWeek < 0 || this.dayOfWeek > 6 || !isValidType(this.dayOfWeek))) {
return false;
}
if (this.hour !== null && (this.hour < 0 || this.hour > 23 || !isValidType(this.hour))) {
return false;
}
if (this.minute !== null && (this.minute < 0 || this.minute > 59 || !isValidType(this.minute))) {
return false;
}
if (this.second !== null && (this.second < 0 || this.second > 59 || !isValidType(this.second))) {
return false;
}
if (this.date !== null) {
if(!isValidType(this.date)) {
return false;
}
switch (this.month) {
case 3:
case 5:
case 8:
case 10:
if (this.date < 1 || this. date > 30) {
return false;
}
break;
case 1:
if (this.date < 1 || this. date > 29) {
return false;
}
break;
default:
if (this.date < 1 || this. date > 31) {
return false;
}
}
}
return true;
};
RecurrenceRule.prototype.nextInvocationDate = function(base) {
base = ((base instanceof CronDate) || (base instanceof Date)) ? base : (new Date());
if (!this.recurs) {
return null;
}
if(!this.isValid()) {
return null;
}
var now = new CronDate(Date.now(), this.tz);
var fullYear = now.getFullYear();
if ((this.year !== null) &&
(typeof this.year == 'number') &&
(this.year < fullYear)) {
return null;
}
var next = new CronDate(base.getTime(), this.tz);
next.addSecond();
while (true) {
if (this.year !== null) {
fullYear = next.getFullYear();
if ((typeof this.year == 'number') && (this.year < fullYear)) {
next = null;
break;
}
if (!recurMatch(fullYear, this.year)) {
next.addYear();
next.setMonth(0);
next.setDate(1);
next.setHours(0);
next.setMinutes(0);
next.setSeconds(0);
continue;
}
}
if (this.month != null && !recurMatch(next.getMonth(), this.month)) {
next.addMonth();
continue;
}
if (this.date != null && !recurMatch(next.getDate(), this.date)) {
next.addDay();
continue;
}
if (this.dayOfWeek != null && !recurMatch(next.getDay(), this.dayOfWeek)) {
next.addDay();
continue;
}
if (this.hour != null && !recurMatch(next.getHours(), this.hour)) {
next.addHour();
continue;
}
if (this.minute != null && !recurMatch(next.getMinutes(), this.minute)) {
next.addMinute();
continue;
}
if (this.second != null && !recurMatch(next.getSeconds(), this.second)) {
next.addSecond();
continue;
}
break;
}
return next ? next.toDate() : null;
};
function recurMatch(val, matcher) {
if (matcher == null) {
return true;
}
if (typeof matcher === 'number') {
return (val === matcher);
} else if(typeof matcher === 'string') {
return (val === Number(matcher));
} else if (matcher instanceof Range) {
return matcher.contains(val);
} else if (Array.isArray(matcher) || (matcher instanceof Array)) {
for (var i = 0; i < matcher.length; i++) {
if (recurMatch(val, matcher[i])) {
return true;
}
}
}
return false;
}
/* Date-based scheduler */
function runOnDate(date, job) {
var now = Date.now();
var then = date.getTime();
return lt.setTimeout(function() {
if (then > Date.now())
runOnDate(date, job);
else
job();
}, (then < now ? 0 : then - now));
}
var invocations = [];
var currentInvocation = null;
function scheduleInvocation(invocation) {
sorted.add(invocations, invocation, sorter);
prepareNextInvocation();
var date = invocation.fireDate instanceof CronDate ? invocation.fireDate.toDate() : invocation.fireDate;
invocation.job.emit('scheduled', date);
}
function prepareNextInvocation() {
if (invocations.length > 0 && currentInvocation !== invocations[0]) {
if (currentInvocation !== null) {
lt.clearTimeout(currentInvocation.timerID);
currentInvocation.timerID = null;
currentInvocation = null;
}
currentInvocation = invocations[0];
var job = currentInvocation.job;
var cinv = currentInvocation;
currentInvocation.timerID = runOnDate(currentInvocation.fireDate, function() {
currentInvocationFinished();
if (job.callback) {
job.callback();
}
if (cinv.recurrenceRule.recurs || cinv.recurrenceRule._endDate === null) {
var inv = scheduleNextRecurrence(cinv.recurrenceRule, cinv.job, cinv.fireDate, cinv.endDate);
if (inv !== null) {
inv.job.trackInvocation(inv);
}
}
job.stopTrackingInvocation(cinv);
job.invoke(cinv.fireDate instanceof CronDate ? cinv.fireDate.toDate() : cinv.fireDate);
job.emit('run');
});
}
}
function currentInvocationFinished() {
invocations.shift();
currentInvocation = null;
prepareNextInvocation();
}
function cancelInvocation(invocation) {
var idx = invocations.indexOf(invocation);
if (idx > -1) {
invocations.splice(idx, 1);
if (invocation.timerID !== null) {
lt.clearTimeout(invocation.timerID);
}
if (currentInvocation === invocation) {
currentInvocation = null;
}
invocation.job.emit('canceled', invocation.fireDate);
prepareNextInvocation();
}
}
/* Recurrence scheduler */
function scheduleNextRecurrence(rule, job, prevDate, endDate) {
prevDate = (prevDate instanceof CronDate) ? prevDate : new CronDate();
var date = (rule instanceof RecurrenceRule) ? rule.nextInvocationDate(prevDate) : rule.next();
if (date === null) {
return null;
}
if ((endDate instanceof CronDate) && date.getTime() > endDate.getTime()) {
return null;
}
var inv = new Invocation(job, date, rule, endDate);
scheduleInvocation(inv);
return inv;
}
/* Convenience methods */
function scheduleJob() {
if (arguments.length < 2) {
return null;
}
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, callback);
if (job.schedule(spec)) {
return job;
}
return null;
}
function rescheduleJob(job, spec) {
if (job instanceof Job) {
if (job.reschedule(spec)) {
return job;
}
} else if (typeof job == 'string' || job instanceof String) {
if (job in scheduledJobs && scheduledJobs.hasOwnProperty(job)) {
if (scheduledJobs[job].reschedule(spec)) {
return scheduledJobs[job];
}
}
}
return null;
}
function cancelJob(job) {
var success = false;
if (job instanceof Job) {
success = job.cancel();
} else if (typeof job == 'string' || job instanceof String) {
if (job in scheduledJobs && scheduledJobs.hasOwnProperty(job)) {
success = scheduledJobs[job].cancel();
}
}
return success;
}
/* Public API */
module.exports.Job = Job;
module.exports.Range = Range;
module.exports.RecurrenceRule = RecurrenceRule;
module.exports.Invocation = Invocation;
module.exports.scheduleJob = scheduleJob;
module.exports.rescheduleJob = rescheduleJob;
module.exports.scheduledJobs = scheduledJobs;
module.exports.cancelJob = cancelJob;

70
nodejs/node_modules/node-schedule/package.json generated vendored Executable file
View File

@ -0,0 +1,70 @@
{
"_args": [
[
"node-schedule@1.3.0",
"/www/wwwroot/Adminx.cc/nodejs"
]
],
"_from": "node-schedule@1.3.0",
"_id": "node-schedule@1.3.0",
"_inBundle": false,
"_integrity": "sha512-NNwO9SUPjBwFmPh3vXiPVEhJLn4uqYmZYvJV358SRGM06BR4UoIqxJpeJwDDXB6atULsgQA97MfD1zMd5xsu+A==",
"_location": "/node-schedule",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "node-schedule@1.3.0",
"name": "node-schedule",
"escapedName": "node-schedule",
"rawSpec": "1.3.0",
"saveSpec": null,
"fetchSpec": "1.3.0"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/node-schedule/-/node-schedule-1.3.0.tgz",
"_spec": "1.3.0",
"_where": "/www/wwwroot/Adminx.cc/nodejs",
"author": {
"name": "Matt Patenaude",
"email": "matt@mattpatenaude.com",
"url": "http://mattpatenaude.com"
},
"bugs": {
"url": "https://github.com/node-schedule/node-schedule/issues"
},
"dependencies": {
"cron-parser": "^2.4.0",
"long-timeout": "0.1.1",
"sorted-array-functions": "^1.0.0"
},
"description": "A cron-like and not-cron-like job scheduler for Node.",
"devDependencies": {
"coveralls": "^2.11.2",
"eslint": "^3.19.0",
"istanbul": "^0.4.5",
"nodeunit": "^0.10.2",
"sinon": "^1.14.1"
},
"homepage": "https://github.com/node-schedule/node-schedule#readme",
"keywords": [
"schedule",
"task",
"job",
"cron"
],
"license": "MIT",
"main": "./lib/schedule.js",
"name": "node-schedule",
"repository": {
"type": "git",
"url": "git+https://github.com/node-schedule/node-schedule.git"
},
"scripts": {
"lint": "eslint lib test",
"test": "nodeunit"
},
"version": "1.3.0"
}

5
nodejs/node_modules/node-schedule/test/.eslintrc generated vendored Executable file
View File

@ -0,0 +1,5 @@
{
"rules": {
"quotes": ["off"]
}
}

View File

@ -0,0 +1,24 @@
'use strict';
var schedule = require('../lib/schedule');
module.exports = {
'Cancel Long Running Job': {
'should work even when recurring jobs are to be run on the past': function (test) {
var ok = true;
var job = schedule.scheduleJob('*/1 * * * * *', function () {
test.ok(ok);
var time = Date.now();
while (ok && (Date.now() - time < 2000)) {
}
});
test.ok(job);
setTimeout(function () {
job.cancel();
test.done();
ok = false;
}, 2100);
}
}
};

View File

@ -0,0 +1,713 @@
'use strict';
var sinon = require('sinon');
var main = require('../package.json').main;
var schedule = require('../' + main);
var clock;
module.exports = {
setUp: function(cb) {
clock = sinon.useFakeTimers();
cb();
},
".scheduleJob": {
"Returns Job instance": function(test) {
var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {});
test.ok(job instanceof schedule.Job);
job.cancel();
test.done();
}
},
".scheduleJob(Date, fn)": {
"Runs job once at some date": function(test) {
test.expect(1);
schedule.scheduleJob(new Date(Date.now() + 3000), function() {
test.ok(true);
});
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Job doesn't emit initial 'scheduled' event": function(test) {
var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {});
job.on('scheduled', function() {
test.ok(false);
});
setTimeout(function() {
test.done();
}, 1250);
clock.tick(1250);
},
"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);
});
test.equal(job, null);
setTimeout(function() {
test.done();
}, 1000);
clock.tick(1000);
}
},
".scheduleJob(RecurrenceRule, fn)": {
"Runs job at interval based on recur rule, repeating indefinitely": function(test) {
test.expect(3);
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Job doesn't emit initial 'scheduled' event": function(test) {
/*
* If this was Job#schedule it'd fire 4 times.
*/
test.expect(3);
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = new schedule.scheduleJob(rule, function() {});
job.on('scheduled', function(runOnDate) {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"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() {
test.ok(false);
});
test.equal(job, null);
setTimeout(function() {
test.done();
}, 1000);
clock.tick(1000);
}
},
".scheduleJob({...}, fn)": {
"Runs job at interval based on object, repeating indefinitely": function(test) {
test.expect(3);
var job = new schedule.scheduleJob({
second: null // Fire every second
}, function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Job doesn't emit initial 'scheduled' event": function(test) {
/*
* With Job#schedule this would be 3:
* scheduled at time 0
* scheduled at time 1000
* scheduled at time 2000
*/
test.expect(2);
var job = schedule.scheduleJob({
second: null // fire every second
}, function() {});
job.on('scheduled', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, 2250);
clock.tick(2250);
},
"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() {
test.done();
}, 1000);
clock.tick(1000);
}
},
".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);
}
},
".rescheduleJob(job, {...})": {
"Reschedule jobs from object based to object based": function(test) {
test.expect(3);
var job = new schedule.scheduleJob({
second: null
}, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job, {
minute: null
});
}, 3250);
setTimeout(function() {
job.cancel();
test.done();
}, 5000);
clock.tick(5000);
},
"Reschedule jobs from every minutes to every second": function(test) {
test.expect(3);
var timeout = 60 * 1000;
var job = new schedule.scheduleJob({
minute: null
}, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job, {
second: null
});
}, timeout);
setTimeout(function() {
job.cancel();
test.done();
}, timeout + 2250);
clock.tick(timeout + 2250);
}
},
".rescheduleJob(job, Date)": {
"Reschedule jobs from Date to Date": function(test) {
test.expect(1);
var job = new schedule.scheduleJob(new Date(Date.now() + 3000), function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job, new Date(Date.now() + 5000));
}, 1000);
setTimeout(function() {
test.done();
}, 6150);
clock.tick(6150);
},
"Reschedule jobs that has been executed": function(test) {
test.expect(2);
var job = new schedule.scheduleJob(new Date(Date.now() + 1000), function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job, new Date(Date.now() + 2000));
}, 2000);
setTimeout(function() {
test.done();
}, 5150);
clock.tick(5150);
}
},
".rescheduleJob(job, RecurrenceRule)": {
"Reschedule jobs from RecurrenceRule to RecurrenceRule": function(test) {
test.expect(3);
var timeout = 60 * 1000;
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
var newRule = new schedule.RecurrenceRule();
newRule.minute = null;
setTimeout(function() {
schedule.rescheduleJob(job, newRule);
}, 2250);
setTimeout(function() {
job.cancel();
test.done();
}, timeout + 2250);
clock.tick(timeout + 2250);
},
"Reschedule jobs from RecurrenceRule to Date": function(test) {
test.expect(3);
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job, new Date(Date.now() + 2000));
}, 2150);
setTimeout(function() {
test.done();
}, 4250);
clock.tick(4250);
},
"Reschedule jobs from RecurrenceRule to {...}": function(test) {
test.expect(3);
var timeout = 60 * 1000;
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job, {
minute: null
});
}, 2150);
setTimeout(function() {
job.cancel();
test.done();
}, timeout + 2150);
clock.tick(timeout + 2150);
},
"Reschedule jobs that is not available": function(test) {
test.expect(4);
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(null, new Date(Date.now() + 2000));
}, 2150);
setTimeout(function() {
job.cancel();
test.done();
}, 4250);
clock.tick(4250);
}
},
'.rescheduleJob("job name", {...})': {
"Reschedule jobs from object based to object based": function(test) {
test.expect(3);
var job = new schedule.scheduleJob({
second: null
}, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job.name, {
minute: null
});
}, 3250);
setTimeout(function() {
job.cancel();
test.done();
}, 5000);
clock.tick(5000);
},
"Reschedule jobs from every minutes to every second": function(test) {
test.expect(3);
var timeout = 60 * 1000;
var job = new schedule.scheduleJob({
minute: null
}, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job.name, {
second: null
});
}, timeout);
setTimeout(function() {
job.cancel();
test.done();
}, timeout + 2250);
clock.tick(timeout + 2250);
}
},
'.rescheduleJob("job name", Date)': {
"Reschedule jobs from Date to Date": function(test) {
test.expect(1);
var job = new schedule.scheduleJob(new Date(Date.now() + 3000), function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job.name, new Date(Date.now() + 5000));
}, 1000);
setTimeout(function() {
test.done();
}, 6150);
clock.tick(6150);
},
"Reschedule jobs that has been executed": function(test) {
test.expect(2);
var job = new schedule.scheduleJob(new Date(Date.now() + 1000), function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job.name, new Date(Date.now() + 2000));
}, 2000);
setTimeout(function() {
test.done();
}, 5150);
clock.tick(5150);
}
},
'.rescheduleJob("job name", RecurrenceRule)': {
"Reschedule jobs from RecurrenceRule to RecurrenceRule": function(test) {
test.expect(3);
var timeout = 60 * 1000;
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
var newRule = new schedule.RecurrenceRule();
newRule.minute = null;
setTimeout(function() {
schedule.rescheduleJob(job.name, newRule);
}, 2250);
setTimeout(function() {
job.cancel();
test.done();
}, timeout + 2250);
clock.tick(timeout + 2250);
},
"Reschedule jobs from RecurrenceRule to Date": function(test) {
test.expect(3);
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job.name, new Date(Date.now() + 2000));
}, 2150);
setTimeout(function() {
test.done();
}, 4250);
clock.tick(4250);
},
"Reschedule jobs from RecurrenceRule to {...}": function(test) {
test.expect(3);
var timeout = 60 * 1000;
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob(job.name, {
minute: null
});
}, 2150);
setTimeout(function() {
job.cancel();
test.done();
}, timeout + 2150);
clock.tick(timeout + 2150);
},
"Reschedule jobs that is not available": function(test) {
test.expect(4);
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
var job = schedule.scheduleJob(rule, function() {
test.ok(true);
});
setTimeout(function() {
schedule.rescheduleJob("Blah", new Date(Date.now() + 2000));
}, 2150);
setTimeout(function() {
job.cancel();
test.done();
}, 4250);
clock.tick(4250);
}
},
".cancelJob(Job)": {
"Prevents all future invocations of Job passed in": function(test) {
test.expect(2);
var job = schedule.scheduleJob({
second: null
}, function() {
test.ok(true);
});
setTimeout(function() {
schedule.cancelJob(job);
}, 2250);
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Can cancel Jobs scheduled with Job#schedule": function(test) {
test.expect(2);
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule({
second: null
});
setTimeout(function() {
schedule.cancelJob(job);
}, 2250);
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Job emits 'canceled' event": function(test) {
test.expect(1);
var job = schedule.scheduleJob({
second: null
}, function() {});
job.on('canceled', function() {
test.ok(true);
});
setTimeout(function() {
schedule.cancelJob(job);
test.done();
}, 1250);
clock.tick(1250);
}
},
'.cancelJob("job name")': {
"Prevents all future invocations of Job identified by name": function(test) {
test.expect(2);
var job = schedule.scheduleJob({
second: null
}, function() {
test.ok(true);
});
setTimeout(function() {
schedule.cancelJob(job.name);
}, 2250);
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
/*
"Can cancel Jobs scheduled with Job#schedule": function(test) {
test.expect(2);
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule({
second: null
});
setTimeout(function() {
schedule.cancelJob(job.name);
}, 2250);
setTimeout(function() {
test.done();
}, 3250);
},*/
"Job emits 'canceled' event": function(test) {
test.expect(1);
var job = schedule.scheduleJob({
second: null
}, function() {});
job.on('canceled', function() {
test.ok(true);
});
setTimeout(function() {
schedule.cancelJob(job.name);
test.done();
}, 1250);
clock.tick(1250);
},
"Does nothing if no job found by that name": function(test) {
test.expect(3);
var job = schedule.scheduleJob({
second: null
}, function() {
test.ok(true);
});
setTimeout(function() {
// This cancel should not affect anything
schedule.cancelJob('blah');
}, 2250);
setTimeout(function() {
job.cancel(); // prevent tests from hanging
test.done();
}, 3250);
clock.tick(3250);
}
},
'.pendingInvocations()': {
"Retrieves pendingInvocations of the job": function(test) {
var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {});
test.ok(job instanceof schedule.Job);
test.ok(job.pendingInvocations()[0].job);
job.cancel();
test.done();
}
},
tearDown: function(cb) {
clock.restore();
cb();
}
};

View File

@ -0,0 +1,59 @@
'use strict';
var sinon = require('sinon');
var main = require('../package.json').main;
var schedule = require('../' + main);
var clock;
module.exports = {
setUp: function(cb) {
clock = sinon.useFakeTimers();
cb();
},
"Date string": {
"Should accept a valid date string": function(test) {
test.expect(1);
schedule.scheduleJob(new Date(Date.now() + 1000).toString(), function() {
test.ok(true);
});
setTimeout(function() {
test.done();
}, 1250);
clock.tick(1250);
},
"Should not accept invalid string as valid date": function(test) {
test.expect(1);
var job = schedule.scheduleJob("hello!!", function() {
});
test.equal(job, null);
test.done();
}
},
"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) {
clock.restore();
cb();
}
};

33
nodejs/node_modules/node-schedule/test/es6/job-test.js generated vendored Executable file
View File

@ -0,0 +1,33 @@
'use strict';
module.exports = function(schedule) {
return {
jobInGenerator: function(test) {
test.expect(1);
var job = new schedule.Job(function*() {
test.ok(true);
});
job.runOnDate(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
},
jobContextInGenerator: function(test) {
test.expect(1);
var job = new schedule.Job('name of job', function*() {
test.ok(this.name === 'name of job');
});
job.runOnDate(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
}
}
}

517
nodejs/node_modules/node-schedule/test/job-test.js generated vendored Executable file
View File

@ -0,0 +1,517 @@
'use strict';
var sinon = require('sinon');
var main = require('../package.json').main;
var schedule = require('../' + main);
var es6;
try {
eval('(function* () {})()');
es6 = require('./es6/job-test')(schedule);
} catch (e) {}
var clock;
module.exports = {
setUp: function(cb) {
clock = sinon.useFakeTimers();
cb();
},
"Job constructor": {
"Accepts Job name and function to run": function(test) {
var job = new schedule.Job('the job', function() {});
test.equal(job.name, 'the job');
test.done();
},
"Job name is optional and will be auto-generated": function(test) {
var job = new schedule.Job();
test.ok(job.name);
test.done();
},
"Uses unique names across auto-generated Job names": function(test) {
var job1 = new schedule.Job();
var job2 = new schedule.Job();
test.notEqual(job1.name, job2.name);
test.done();
}
},
"#schedule(Date)": {
"Runs job once at some date": function(test) {
test.expect(1);
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Cancel next job before it runs": function(test) {
test.expect(1);
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule(new Date(Date.now() + 1500));
job.schedule(new Date(Date.now() + 3000));
job.cancelNext();
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Run job on specified date": function(test) {
test.expect(1);
var job = new schedule.Job(function() {
test.ok(true);
});
job.runOnDate(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Run job in generator": function(test) {
if (!es6) {
test.expect(0);
test.done();
return;
}
es6.jobInGenerator(test);
clock.tick(3250);
},
"Context is passed into generator correctly": function(test) {
if (!es6) {
test.expect(0);
test.done();
return;
}
es6.jobContextInGenerator(test);
clock.tick(3250);
},
"Won't run job if scheduled in the past": function(test) {
test.expect(0);
var job = new schedule.Job(function() {
test.ok(false);
});
job.schedule(new Date(Date.now() - 3000));
setTimeout(function() {
test.done();
}, 1000);
clock.tick(1000);
},
"Jobs still run after scheduling a Job in the past": function(test) {
test.expect(1);
var pastJob = new schedule.Job(function() {
// Should not run, blow up if it does
test.ok(false);
});
pastJob.schedule(new Date(Date.now() - 3000));
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Job emits 'scheduled' event with 'run at' Date": function(test) {
test.expect(1);
var date = new Date(Date.now() + 3000);
var job = new schedule.Job(function() {
test.done();
});
job.on('scheduled', function(runAtDate) {
test.equal(runAtDate.getTime(), date.getTime());
});
job.schedule(date);
clock.tick(3250);
}
},
"#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)": {
"Runs job at interval based on recur rule, repeating indefinitely": function(test) {
test.expect(3);
var job = new schedule.Job(function() {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
job.schedule(rule);
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Job emits 'scheduled' event for every next invocation": function(test) {
// Job will run 3 times but be scheduled 4 times, 4th run never happens
// due to cancel.
test.expect(4);
var job = new schedule.Job(function() {});
job.on('scheduled', function(runOnDate) {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // fire every second
job.schedule(rule);
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Doesn't invoke job if recur rule schedules it in the past": function(test) {
test.expect(0);
var job = new schedule.Job(function() {
test.ok(false);
});
var rule = new schedule.RecurrenceRule();
rule.year = 2000;
job.schedule(rule);
setTimeout(function() {
job.cancel();
test.done();
}, 1000);
clock.tick(1000);
}
},
"#schedule({...})": {
"Runs job at interval based on object, repeating indefinitely": function(test) {
test.expect(3);
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Job emits 'scheduled' event for every next invocation": function(test) {
// Job will run 3 times but be scheduled 4 times, 4th run never happens
// due to cancel.
test.expect(4);
var job = new schedule.Job(function() {});
job.on('scheduled', function(runOnDate) {
test.ok(true);
});
job.schedule({
second: null // Fire every second
});
setTimeout(function() {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
"Doesn't invoke job if object schedules it in the past": function(test) {
test.expect(0);
var job = new schedule.Job(function() {
test.ok(false);
});
job.schedule({
year: 2000
});
setTimeout(function() {
job.cancel();
test.done();
}, 1000);
clock.tick(1000);
}
},
"#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": {
"Prevents all future invocations": function(test) {
test.expect(1);
var job = new schedule.Job(function() {
test.ok(true);
});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
}, 1250);
setTimeout(function() {
test.done();
}, 2250);
clock.tick(2250);
},
"Job emits 'canceled' event": function(test) {
test.expect(1);
var job = new schedule.Job(function() {});
job.on('canceled', function() {
test.ok(true);
});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
}, 1250);
setTimeout(function() {
test.done();
}, 2250);
clock.tick(2250);
},
"Job is added to scheduledJobs when created and removed when cancelled": function(test) {
test.expect(4);
var job1 = new schedule.Job('cancelJob', function() {});
job1.schedule({
second: null // fire every second
});
var job2 = schedule.scheduleJob('second',
{ second: null },
function() {},
function() {});
test.strictEqual(schedule.scheduledJobs.cancelJob, job1);
test.strictEqual(schedule.scheduledJobs.second, job2);
setTimeout(function() {
job1.cancel();
job2.cancel();
test.strictEqual(schedule.scheduledJobs.cancelJob, undefined);
test.strictEqual(schedule.scheduledJobs.second, undefined);
test.done();
}, 1250);
clock.tick(1250);
}
},
"#reschedule": {
"When rescheduled counter will be reset to zero": function(test) {
var job = new schedule.scheduleJob({
second: null
}, function() {});
setTimeout(function() {
test.equal(job.triggeredJobs(), 3);
schedule.rescheduleJob(job, {
minute: null
});
}, 3250);
setTimeout(function() {
job.cancel();
test.equal(job.triggeredJobs(), 0);
test.done();
}, 5000);
clock.tick(5000);
}
},
"When invoked": {
"Job emits 'run' event": function(test) {
test.expect(1);
var job = new schedule.Job(function() {});
job.on('run', function() {
test.ok(true);
});
job.schedule(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
}, 3250);
clock.tick(3250);
},
"Job counter increase properly": function(test) {
var job = new schedule.Job(function() {});
job.schedule({
second: null // fire every second
});
setTimeout(function() {
job.cancel();
test.equal(job.triggeredJobs(), 2);
test.done();
}, 2250);
clock.tick(2250);
},
"Job gets invoked with the fire date": function (test) {
test.expect(2);
var prevFireDate;
var job = new schedule.Job(function (fireDate) {
if (!prevFireDate) {
test.ok(fireDate instanceof Date);
} else {
test.equal(fireDate.getTime() - prevFireDate.getTime(), 1000);
}
prevFireDate = fireDate;
});
job.schedule({
second: null // fire every second
});
setTimeout(function () {
job.cancel();
test.done();
}, 2250);
clock.tick(2250);
}
},
tearDown: function(cb) {
clock.restore();
cb();
}
};

77
nodejs/node_modules/node-schedule/test/range-test.js generated vendored Executable file
View File

@ -0,0 +1,77 @@
'use strict';
var main = require('../package.json').main;
var schedule = require('../' + main);
module.exports = {
"step defaults to 1": function(test) {
var range = new schedule.Range(2, 6);
test.equals(1, range.step);
test.done();
},
"when step is 1": {
"setUp": function(done) {
this.range = new schedule.Range(2, 6, 1);
done();
},
"includes start value": function(test) {
test.ok(this.range.contains(2));
test.done();
},
"includes end value": function(test) {
test.ok(this.range.contains(6));
test.done();
},
"includes value between start and end": function(test) {
test.ok(this.range.contains(3));
test.done();
},
"excludes values outside of start and end": function(test) {
test.ok(!this.range.contains(1));
test.ok(!this.range.contains(7));
test.done();
}
},
"when step > 1": {
"setUp": function(done) {
this.range = new schedule.Range(2, 6, 2);
done();
},
"includes start value": function(test) {
test.ok(this.range.contains(2));
test.done();
},
"excludes end value": function(test) {
test.ok(!this.range.contains(6));
test.done();
},
"includes value between start and end that is evenly divisible by step": function(test) {
test.ok(this.range.contains(4));
test.done();
},
"excludes value between start and end that is not evenly divisible by step": function(test) {
test.ok(!this.range.contains(5));
test.done();
},
"excludes values outside of start and end": function(test) {
test.ok(!this.range.contains(1));
test.ok(!this.range.contains(7));
test.done();
}
}
};

View File

@ -0,0 +1,375 @@
'use strict';
var main = require('../package.json').main;
var schedule = require('../' + main);
var sinon = require('sinon');
var clock;
// 12:30:15 pm Thursday 29 April 2010 in the timezone this code is being run in
var base = new Date(2010, 3, 29, 12, 30, 15, 0);
var baseMs = base.getTime();
module.exports = {
"setUp": function(cb) {
clock = sinon.useFakeTimers(baseMs);
cb();
},
"tearDown": function(cb) {
clock.restore();
cb();
},
"#nextInvocationDate(Date)": {
"next second": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = null;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 12, 30, 16, 0), next);
test.done();
},
"next 25th second": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = 25;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 12, 30, 25, 0), next);
test.done();
},
"next 5th second (minutes incremented)": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = 5;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 12, 31, 5, 0), next);
test.done();
},
"next 40th minute": function(test) {
var rule = new schedule.RecurrenceRule();
rule.minute = 40;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 12, 40, 0, 0), next);
test.done();
},
"next 1st minute (hours incremented)": function(test) {
var rule = new schedule.RecurrenceRule();
rule.minute = 1;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 13, 1, 0, 0), next);
test.done();
},
"next 23rd hour": function(test) {
var rule = new schedule.RecurrenceRule();
rule.hour = 23;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 23, 0, 0, 0), next);
test.done();
},
"next 3rd hour (days incremented)": function(test) {
var rule = new schedule.RecurrenceRule();
rule.hour = 3;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 30, 3, 0, 0, 0), next);
test.done();
},
"next Friday": function(test) {
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = 5;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 30, 0, 0, 0, 0), next);
test.done();
},
"next Monday (months incremented)": function(test) {
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = 1;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 4, 3, 0, 0, 0, 0), next);
test.done();
},
"next 30th date": function(test) {
var rule = new schedule.RecurrenceRule();
rule.date = 30;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 30, 0, 0, 0, 0), next);
test.done();
},
"next 5th date (months incremented)": function(test) {
var rule = new schedule.RecurrenceRule();
rule.date = 5;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 4, 5, 0, 0, 0, 0), next);
test.done();
},
"next October": function(test) {
var rule = new schedule.RecurrenceRule();
rule.month = 9;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 9, 1, 0, 0, 0, 0), next);
test.done();
},
"next February (years incremented)": function(test) {
var rule = new schedule.RecurrenceRule();
rule.month = 1;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2011, 1, 1, 0, 0, 0, 0), next);
test.done();
},
"in the year 2040": function(test) {
var rule = new schedule.RecurrenceRule();
rule.year = 2040;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2040, 0, 1, 0, 0, 0, 0), next);
test.done();
},
"using past year": function(test) {
var rule = new schedule.RecurrenceRule();
rule.year = 2000;
var next = rule.nextInvocationDate(base);
test.equal(null, next);
test.done();
},
"using mixed time components": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = 50;
rule.minute = 5;
rule.hour = 10;
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 30, 10, 5, 50, 0), next);
test.done();
},
/*
"using date and dayOfWeek together": function(test) {
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = 4; // This is Thursday April 1st
rule.date = 10; // This is Saturday April 10th
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 1, 0, 0, 0, 0), next);
test.done();
}*/
"returns null when no invocations left": function(test) {
var rule = new schedule.RecurrenceRule();
rule.year = 2000;
var next = rule.nextInvocationDate(base);
test.strictEqual(null, next);
test.done();
},
"specify span of components using Range": function(test) {
var rule = new schedule.RecurrenceRule();
rule.minute = new schedule.Range(4, 6);
var next;
next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 13, 4, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 5, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 6, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 14, 4, 0, 0), next);
test.done();
},
"specify intervals within span of components using Range with step": function(test) {
var rule = new schedule.RecurrenceRule();
rule.minute = new schedule.Range(4, 8, 2);
var next;
next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 13, 4, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 6, 0, 0), next);
/* Should Range stay inclusive on both ends when step > 1
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 8, 0, 0), next);
*/
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 14, 4, 0, 0), next);
test.done();
},
"specify span and explicit components using Array of Ranges and Numbers": function(test) {
var rule = new schedule.RecurrenceRule();
rule.minute = [2, new schedule.Range(4, 6)];
var next;
next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 29, 13, 2, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 4, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 5, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 13, 6, 0, 0), next);
next = rule.nextInvocationDate(next);
test.deepEqual(new Date(2010, 3, 29, 14, 2, 0, 0), next);
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();
},
"With the year set should not loop indefinetely": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = 0;
rule.minute = 0;
rule.hour = 0;
rule.date = 1;
rule.month = 5;
rule.year = 2010;
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.equal(next, null);
test.done();
},
"using rule with string properties": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = '50';
rule.minute = '5';
rule.hour = '10';
var next = rule.nextInvocationDate(base);
test.deepEqual(new Date(2010, 3, 30, 10, 5, 50, 0), next);
test.done();
},
"nextInvocationDate on an invalid month should return null": function(test) {
var rule = new schedule.RecurrenceRule();
rule.month = 12;
var next = rule.nextInvocationDate();
test.equal(next, null);
var rule2 = new schedule.RecurrenceRule();
rule2.month = 'asdfasdf';
var next2 = rule2.nextInvocationDate(next);
test.equal(next2, null);
test.done();
},
"nextInvocationDate on an invalid second should return null": function(test) {
var rule = new schedule.RecurrenceRule();
rule.second = 60;
var next = rule.nextInvocationDate();
test.equal(next, null);
var rule2 = new schedule.RecurrenceRule();
rule2.second = 'asdfasdf';
var next2 = rule2.nextInvocationDate();
test.equal(next2, null);
test.done();
},
"nextInvocationDate on an invalid hour should return null": function(test) {
var rule = new schedule.RecurrenceRule();
rule.hour = 24;
var next = rule.nextInvocationDate();
test.equal(next, null);
var rule2 = new schedule.RecurrenceRule();
rule2.hour = 'asdfasdf';
var next2 = rule2.nextInvocationDate();
test.equal(next2, null);
test.done();
},
"nextInvocationDate on an invalid date should return null": function(test) {
var rule = new schedule.RecurrenceRule();
rule.date = 90;
var next = rule.nextInvocationDate();
test.equal(next, null);
// Test February
var rule2 = new schedule.RecurrenceRule();
rule2.month = 1;
rule2.date = 30;
var next2 = rule2.nextInvocationDate();
test.equal(next2, null);
var rule3 = new schedule.RecurrenceRule();
rule3.date = 'asdfasdf';
var next3 = rule3.nextInvocationDate();
test.equal(next3, null);
test.done();
},
"nextInvocationDate on an invalid dayOfWeek should return null": function(test) {
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = 90;
var next = rule.nextInvocationDate();
test.equal(next, null);
var rule2 = new schedule.RecurrenceRule();
rule2.dayOfWeek = 'asdfasdf';
var next2 = rule.nextInvocationDate();
test.equal(next2, null);
test.done();
}
}
};

134
nodejs/node_modules/node-schedule/test/schedule-cron-jobs.js generated vendored Executable file
View File

@ -0,0 +1,134 @@
'use strict';
var sinon = require('sinon');
var main = require('../package.json').main;
var schedule = require('../' + main);
var clock;
module.exports = {
".scheduleJob(cron_expr, fn)": {
setUp: function(cb) {
clock = sinon.useFakeTimers();
cb();
},
"Runs job every second": function(test) {
test.expect(3);
var timeout = 3 * 1000 + 150;
var job = schedule.scheduleJob('* * * * * *', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
"Runs job every minute": function(test) {
test.expect(3);
var timeout = 3 * 60 * 1000 + 150;
var job = schedule.scheduleJob('0 * * * * *', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
"Runs job every hour": function(test) {
test.expect(3);
var timeout = 3 * 60 * 60 * 1000 + 150;
var job = schedule.scheduleJob('0 0 * * * *', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
"Runs job every day": function(test) {
test.expect(3);
var timeout = 3 * 24 * 60 * 60 * 1000 + 150;
var job = schedule.scheduleJob('0 0 0 * * *', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
"Runs job every week": function(test) {
test.expect(3);
var timeout = 3 * 7 * 24 * 60 * 60 * 1000 + 150;
var job = schedule.scheduleJob('0 0 0 * * 1', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
"Runs job every month": function(test) {
test.expect(48);
var timeout = 4 * 365.25 * 24 * 60 * 60 * 1000 + 150;
var job = schedule.scheduleJob('0 0 0 1 * *', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
"Runs job every year": function(test) {
test.expect(4);
var timeout = 4 * 365.25 * 24 * 60 * 60 * 1000 + 150;
var job = schedule.scheduleJob('0 0 0 1 1 *', function() {
test.ok(true);
});
setTimeout(function() {
job.cancel();
test.done();
}, timeout);
clock.tick(timeout);
},
tearDown: function(cb) {
clock.restore();
cb();
}
}
};

327
nodejs/node_modules/node-schedule/test/start-end-test.js generated vendored Executable file
View File

@ -0,0 +1,327 @@
'use strict';
var sinon = require('sinon');
var main = require('../package.json').main;
var schedule = require('../' + main);
var clock;
module.exports = {
setUp: function (cb) {
clock = sinon.useFakeTimers();
cb();
},
'RecurrenceRule': {
'no endTime , startTime less than now': function (test) {
test.expect(3);
var job = new schedule.Job(function () {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // every second
job.schedule({
start: new Date(Date.now() - 2000),
rule: rule
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no endTime , startTime greater than now': function (test) {
test.expect(1);
var job = new schedule.Job(function () {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // every second
job.schedule({
start: new Date(Date.now() + 2000),
rule: rule
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no startTime , endTime less than now': function (test) {
test.expect(0);
var job = new schedule.Job(function () {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // every second
job.schedule({
end: new Date(Date.now() - 2000),
rule: rule
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no startTime , endTime greater than now': function (test) {
test.expect(2);
var job = new schedule.Job(function () {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // every second
job.schedule({
end: new Date(Date.now() + 2000),
rule: rule
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'has startTime and endTime': function (test) {
test.expect(1);
var job = new schedule.Job(function () {
test.ok(true);
});
var rule = new schedule.RecurrenceRule();
rule.second = null; // every second
job.schedule({
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 2000),
rule: rule
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
}
},
'Object Literal': {
'no endTime , startTime less than now': function (test) {
test.expect(3);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
start: new Date(Date.now() - 2000),
rule: { second: null }
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no endTime , startTime greater than now': function (test) {
test.expect(1);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
start: new Date(Date.now() + 2000),
rule: { second: null }
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no startTime , endTime less than now': function (test) {
test.expect(0);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
end: new Date(Date.now() - 2000),
rule: { second: null }
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no startTime , endTime greater than now': function (test) {
test.expect(2);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
end: new Date(Date.now() + 2000),
rule: { second: null }
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'has startTime and endTime': function (test) {
test.expect(1);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 2000),
rule: { second: null }
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
}
},
'cron-style': {
'no endTime , startTime less than now': function (test) {
test.expect(3);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
start: new Date(Date.now() - 2000),
rule: '*/1 * * * * *'
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no endTime , startTime greater than now': function (test) {
test.expect(1);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
start: new Date(Date.now() + 2000),
rule: '*/1 * * * * *'
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no startTime , endTime less than now': function (test) {
test.expect(0);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
end: new Date(Date.now() - 2000),
rule: '*/1 * * * * *'
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'no startTime , endTime greater than now': function (test) {
test.expect(2);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
end: new Date(Date.now() + 2000),
rule: '*/1 * * * * *'
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
},
'has startTime and endTime': function (test) {
test.expect(1);
var job = new schedule.Job(function () {
test.ok(true);
});
job.schedule({
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 2000),
rule: '*/1 * * * * *'
});
setTimeout(function () {
job.cancel();
test.done();
}, 3250);
clock.tick(3250);
}
},
tearDown: function (cb) {
clock.restore();
cb();
}
};