Initial import from local backup (Documents-Playground/pakerpale)
This commit is contained in:
1
node_modules/node-cron/.covignore
generated
vendored
Normal file
1
node_modules/node-cron/.covignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/node_modules/
|
||||
17
node_modules/node-cron/.github/stale.yml
generated
vendored
Normal file
17
node_modules/node-cron/.github/stale.yml
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 60
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: wontfix
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
||||
3
node_modules/node-cron/.hound.yml
generated
vendored
Normal file
3
node_modules/node-cron/.hound.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
javascript:
|
||||
config_file: .jshintrc
|
||||
ignore_file: .jshintignore
|
||||
3
node_modules/node-cron/.jshintignore
generated
vendored
Normal file
3
node_modules/node-cron/.jshintignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
coverage/
|
||||
covreporter/
|
||||
35
node_modules/node-cron/.jshintrc
generated
vendored
Normal file
35
node_modules/node-cron/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"esversion": 6,
|
||||
"node": true,
|
||||
"bitwise": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"forin": true,
|
||||
"freeze": true,
|
||||
"funcscope": false,
|
||||
"globals": false,
|
||||
"latedef": true,
|
||||
"maxcomplexity": 8,
|
||||
"maxparams": 4,
|
||||
"nonbsp": true,
|
||||
"nonew": false,
|
||||
"quotmark": "single",
|
||||
"shadow": false,
|
||||
"strict": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": false,
|
||||
"debug": false,
|
||||
"eqnull": false,
|
||||
"evil": false,
|
||||
"noyield": true,
|
||||
|
||||
"predef": [
|
||||
"beforeEach",
|
||||
"afterEach",
|
||||
"describe",
|
||||
"it"
|
||||
]
|
||||
}
|
||||
10
node_modules/node-cron/.travis.yml
generated
vendored
Normal file
10
node_modules/node-cron/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "8"
|
||||
before_script:
|
||||
- export TZ=America/Sao_Paulo
|
||||
- echo '$TZ' | sudo tee /etc/timezone
|
||||
- sudo dpkg-reconfigure --frontend noninteractive tzdata
|
||||
- npm install
|
||||
script:
|
||||
- npm run check
|
||||
7
node_modules/node-cron/LICENSE.md
generated
vendored
Normal file
7
node_modules/node-cron/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
## ISC License
|
||||
|
||||
Copyright (c) 2016, Lucas Merencia \<lucas.merencia@gmail.com\>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
259
node_modules/node-cron/README.md
generated
vendored
Normal file
259
node_modules/node-cron/README.md
generated
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
# Node Cron
|
||||
|
||||
[](https://github.com/merencia/node-cron/blob/master/LICENSE.md)
|
||||
[](https://img.shields.io/npm/v/node-cron.svg)
|
||||
[](https://coveralls.io/github/node-cron/node-cron?branch=master)
|
||||
[](https://codeclimate.com/github/merencia/node-cron)
|
||||
[](https://travis-ci.org/merencia/node-cron)
|
||||
[](https://david-dm.org/merencia/node-cron)
|
||||
[](https://david-dm.org/merencia/node-cron#info=devDependencies)
|
||||
[](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
The node-cron module is tiny task scheduler in pure JavaScript for node.js based on [GNU crontab](https://www.gnu.org/software/mcron/manual/html_node/Crontab-file.html). This module allows you to schedule task in node.js using full crontab syntax.
|
||||
|
||||
[](https://nodei.co/npm/node-cron/)
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
Install node-cron using npm:
|
||||
|
||||
```console
|
||||
$ npm install --save node-cron
|
||||
```
|
||||
|
||||
Import node-cron and schedule a task:
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('* * * * *', () => {
|
||||
console.log('running a task every minute');
|
||||
});
|
||||
```
|
||||
|
||||
## Cron Syntax
|
||||
|
||||
This is a quick reference to cron syntax and also shows the options supported by node-cron.
|
||||
|
||||
### Allowed fields
|
||||
|
||||
```
|
||||
# ┌────────────── second (optional)
|
||||
# │ ┌──────────── minute
|
||||
# │ │ ┌────────── hour
|
||||
# │ │ │ ┌──────── day of month
|
||||
# │ │ │ │ ┌────── month
|
||||
# │ │ │ │ │ ┌──── day of week
|
||||
# │ │ │ │ │ │
|
||||
# │ │ │ │ │ │
|
||||
# * * * * * *
|
||||
```
|
||||
|
||||
### Allowed values
|
||||
|
||||
| field | value |
|
||||
|--------------|---------------------|
|
||||
| second | 0-59 |
|
||||
| minute | 0-59 |
|
||||
| hour | 0-23 |
|
||||
| day of month | 1-31 |
|
||||
| month | 1-12 (or names) |
|
||||
| day of week | 0-7 (or names, 0 or 7 are sunday) |
|
||||
|
||||
|
||||
#### Using multiples values
|
||||
|
||||
You may use multiples values separated by comma:
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('1,2,4,5 * * * *', () => {
|
||||
console.log('running every minute 1, 2, 4 and 5');
|
||||
});
|
||||
```
|
||||
|
||||
#### Using ranges
|
||||
|
||||
You may also define a range of values:
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('1-5 * * * *', () => {
|
||||
console.log('running every minute to 1 from 5');
|
||||
});
|
||||
```
|
||||
|
||||
#### Using step values
|
||||
|
||||
Step values can be used in conjunction with ranges, following a range with '/' and a number. e.g: `1-10/2` that is the same as `2,4,6,8,10`. Steps are also permitted after an asterisk, so if you want to say “every two minutes”, just use `*/2`.
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('*/2 * * * *', () => {
|
||||
console.log('running a task every two minutes');
|
||||
});
|
||||
```
|
||||
|
||||
#### Using names
|
||||
|
||||
For month and week day you also may use names or short names. e.g:
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('* * * January,September Sunday', () => {
|
||||
console.log('running on Sundays of January and September');
|
||||
});
|
||||
```
|
||||
|
||||
Or with short names:
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('* * * Jan,Sep Sun', () => {
|
||||
console.log('running on Sundays of January and September');
|
||||
});
|
||||
```
|
||||
|
||||
## Cron methods
|
||||
|
||||
### Schedule
|
||||
|
||||
Schedules given task to be executed whenever the cron expression ticks.
|
||||
|
||||
Arguments:
|
||||
|
||||
- **expression** `string`: Cron expression
|
||||
- **function** `Function`: Task to be executed
|
||||
- **options** `Object`: Optional configuration for job scheduling.
|
||||
|
||||
#### Options
|
||||
|
||||
- **scheduled**: A `boolean` to set if the created task is schaduled. Default `true`;
|
||||
- **timezone**: The timezone that is used for job scheduling;
|
||||
|
||||
**Example**:
|
||||
|
||||
```js
|
||||
var cron = require('node-cron');
|
||||
|
||||
cron.schedule('0 1 * * *', () => {
|
||||
console.log('Runing a job at 01:00 at America/Sao_Paulo timezone');
|
||||
}, {
|
||||
scheduled: true,
|
||||
timezone: "America/Sao_Paulo"
|
||||
});
|
||||
```
|
||||
|
||||
## ScheduledTask methods
|
||||
|
||||
### Start
|
||||
|
||||
Starts the scheduled task.
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
var task = cron.schedule('* * * * *', () => {
|
||||
console.log('stoped task');
|
||||
}, {
|
||||
scheduled: false
|
||||
});
|
||||
|
||||
task.start();
|
||||
```
|
||||
|
||||
### Stop
|
||||
|
||||
The task won't be executed unless re-started.
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
var task = cron.schedule('* * * * *', () => {
|
||||
console.log('will execute every minute until stopped');
|
||||
});
|
||||
|
||||
task.stop();
|
||||
```
|
||||
|
||||
### Destroy
|
||||
|
||||
The task will be stopped and completely destroyed.
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
var task = cron.schedule('* * * * *', () => {
|
||||
console.log('will not execute anymore, nor be able to restart');
|
||||
});
|
||||
|
||||
task.destroy();
|
||||
```
|
||||
|
||||
### Validate
|
||||
|
||||
Validate that the given string is a valid cron expression.
|
||||
|
||||
```javascript
|
||||
var cron = require('node-cron');
|
||||
|
||||
var valid = cron.validate('59 * * * *');
|
||||
var invalid = cron.validate('60 * * * *');
|
||||
```
|
||||
|
||||
## Issues
|
||||
|
||||
Feel free to submit issues and enhancement requests [here](https://github.com/merencia/node-cron/issues).
|
||||
|
||||
## Contributors
|
||||
|
||||
In general, we follow the "fork-and-pull" Git workflow.
|
||||
|
||||
- Fork the repo on GitHub;
|
||||
- Commit changes to a branch in your fork;
|
||||
- Pull request "upstream" with your changes;
|
||||
|
||||
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
|
||||
|
||||
Please do not contribute code you did not write yourself, unless you are certain you have the legal ability to do so. Also ensure all contributed code can be distributed under the ISC License.
|
||||
|
||||
## Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute.
|
||||
<a href="graphs/contributors"><img src="https://opencollective.com/node-cron/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
|
||||
## Backers
|
||||
|
||||
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/node-cron#backer)]
|
||||
|
||||
<a href="https://opencollective.com/node-cron#backers" target="_blank"><img src="https://opencollective.com/node-cron/backers.svg?width=890"></a>
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/node-cron#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/node-cron/sponsor/0/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/1/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/2/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/3/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/4/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/5/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/6/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/7/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/8/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/node-cron/sponsor/9/website" target="_blank"><img src="https://opencollective.com/node-cron/sponsor/9/avatar.svg"></a>
|
||||
|
||||
|
||||
|
||||
## License
|
||||
|
||||
node-cron is under [ISC License](https://github.com/merencia/node-cron/blob/master/LICENSE.md).
|
||||
79
node_modules/node-cron/package.json
generated
vendored
Normal file
79
node_modules/node-cron/package.json
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"_from": "node-cron",
|
||||
"_id": "node-cron@2.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-eJI+QitXlwcgiZwNNSRbqsjeZMp5shyajMR81RZCqeW0ZDEj4zU9tpd4nTh/1JsBiKbF8d08FCewiipDmVIYjg==",
|
||||
"_location": "/node-cron",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "node-cron",
|
||||
"name": "node-cron",
|
||||
"escapedName": "node-cron",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/node-cron/-/node-cron-2.0.3.tgz",
|
||||
"_shasum": "b9649784d0d6c00758410eef22fa54a10e3f602d",
|
||||
"_spec": "node-cron",
|
||||
"_where": "D:\\dev\\crossmap\\backend-services\\cm-app-crawlspider",
|
||||
"author": {
|
||||
"name": "Lucas Merencia"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/merencia/node-cron/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"collective": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/node-cron",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "^13.0.1",
|
||||
"sinon": "^6.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"opencollective-postinstall": "^2.0.0",
|
||||
"tz-offset": "0.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A simple cron-like task scheduler for Node.js",
|
||||
"devDependencies": {
|
||||
"coveralls": "^3.0.2",
|
||||
"expect.js": "^0.3.1",
|
||||
"istanbul": "^0.4.2",
|
||||
"mocha": "^4.0.1",
|
||||
"nyc": "^13.0.1",
|
||||
"sinon": "^4.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/merencia/node-cron",
|
||||
"keywords": [
|
||||
"cron",
|
||||
"scheduler",
|
||||
"schedule",
|
||||
"task",
|
||||
"job"
|
||||
],
|
||||
"license": "ISC",
|
||||
"main": "src/node-cron.js",
|
||||
"name": "node-cron",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/merencia/node-cron.git"
|
||||
},
|
||||
"scripts": {
|
||||
"check": "npm test && npm run coverage",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"postinstall": "opencollective-postinstall",
|
||||
"test": "nyc --reporter=html --reporter=text mocha --recursive"
|
||||
},
|
||||
"version": "2.0.3"
|
||||
}
|
||||
21
node_modules/node-cron/src/convert-expression/asterisk-to-range-conversion.js
generated
vendored
Normal file
21
node_modules/node-cron/src/convert-expression/asterisk-to-range-conversion.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
module.exports = (() => {
|
||||
function convertAsterisk(expression, replecement){
|
||||
if(expression.indexOf('*') !== -1){
|
||||
return expression.replace('*', replecement);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
function convertAsterisksToRanges(expressions){
|
||||
expressions[0] = convertAsterisk(expressions[0], '0-59');
|
||||
expressions[1] = convertAsterisk(expressions[1], '0-59');
|
||||
expressions[2] = convertAsterisk(expressions[2], '0-23');
|
||||
expressions[3] = convertAsterisk(expressions[3], '1-31');
|
||||
expressions[4] = convertAsterisk(expressions[4], '1-12');
|
||||
expressions[5] = convertAsterisk(expressions[5], '0-6');
|
||||
return expressions;
|
||||
}
|
||||
|
||||
return convertAsterisksToRanges;
|
||||
})();
|
||||
66
node_modules/node-cron/src/convert-expression/index.js
generated
vendored
Normal file
66
node_modules/node-cron/src/convert-expression/index.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
var monthNamesConversion = require('./month-names-conversion');
|
||||
var weekDayNamesConversion = require('./week-day-names-conversion');
|
||||
var convertAsterisksToRanges = require('./asterisk-to-range-conversion');
|
||||
var convertRanges = require('./range-conversion');
|
||||
var convertSteps = require('./step-values-conversion');
|
||||
|
||||
module.exports = (() => {
|
||||
|
||||
function appendSeccondExpression(expressions){
|
||||
if(expressions.length === 5){
|
||||
return ['0'].concat(expressions);
|
||||
}
|
||||
return expressions;
|
||||
}
|
||||
|
||||
function removeSpaces(str) {
|
||||
return str.replace(/\s{2,}/g, ' ').trim();
|
||||
}
|
||||
|
||||
// Function that takes care of normalization.
|
||||
function normalizeIntegers(expressions) {
|
||||
for (var i=0; i < expressions.length; i++){
|
||||
var numbers = expressions[i].split(',');
|
||||
for (var j=0; j<numbers.length; j++){
|
||||
numbers[j] = parseInt(numbers[j]);
|
||||
}
|
||||
expressions[i] = numbers;
|
||||
}
|
||||
return expressions;
|
||||
}
|
||||
|
||||
/*
|
||||
* The node-cron core allows only numbers (including multiple numbers e.g 1,2).
|
||||
* This module is going to translate the month names, week day names and ranges
|
||||
* to integers relatives.
|
||||
*
|
||||
* Month names example:
|
||||
* - expression 0 1 1 January,Sep *
|
||||
* - Will be translated to 0 1 1 1,9 *
|
||||
*
|
||||
* Week day names example:
|
||||
* - expression 0 1 1 2 Monday,Sat
|
||||
* - Will be translated to 0 1 1 1,5 *
|
||||
*
|
||||
* Ranges example:
|
||||
* - expression 1-5 * * * *
|
||||
* - Will be translated to 1,2,3,4,5 * * * *
|
||||
*/
|
||||
function interprete(expression){
|
||||
var expressions = removeSpaces(expression).split(' ');
|
||||
expressions = appendSeccondExpression(expressions);
|
||||
expressions[4] = monthNamesConversion(expressions[4]);
|
||||
expressions[5] = weekDayNamesConversion(expressions[5]);
|
||||
expressions = convertAsterisksToRanges(expressions);
|
||||
expressions = convertRanges(expressions);
|
||||
expressions = convertSteps(expressions);
|
||||
|
||||
expressions = normalizeIntegers(expressions);
|
||||
|
||||
return expressions.join(' ');
|
||||
}
|
||||
|
||||
return interprete;
|
||||
})();
|
||||
22
node_modules/node-cron/src/convert-expression/month-names-conversion.js
generated
vendored
Normal file
22
node_modules/node-cron/src/convert-expression/month-names-conversion.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
module.exports = (() => {
|
||||
var months = ['january','february','march','april','may','june','july',
|
||||
'august','september','october','november','december'];
|
||||
var shortMonths = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
|
||||
'sep', 'oct', 'nov', 'dec'];
|
||||
|
||||
function convertMonthName(expression, items){
|
||||
for(var i = 0; i < items.length; i++){
|
||||
expression = expression.replace(new RegExp(items[i], 'gi'), parseInt(i, 10) + 1);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
function interprete(monthExpression){
|
||||
monthExpression = convertMonthName(monthExpression, months);
|
||||
monthExpression = convertMonthName(monthExpression, shortMonths);
|
||||
return monthExpression;
|
||||
}
|
||||
|
||||
return interprete;
|
||||
})();
|
||||
42
node_modules/node-cron/src/convert-expression/range-conversion.js
generated
vendored
Normal file
42
node_modules/node-cron/src/convert-expression/range-conversion.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
module.exports = ( () => {
|
||||
function replaceWithRange(expression, text, init, end) {
|
||||
|
||||
var numbers = [];
|
||||
var last = parseInt(end);
|
||||
var first = parseInt(init);
|
||||
|
||||
if(first > last){
|
||||
last = parseInt(init);
|
||||
first = parseInt(end);
|
||||
}
|
||||
|
||||
for(var i = first; i <= last; i++) {
|
||||
numbers.push(i);
|
||||
}
|
||||
|
||||
return expression.replace(new RegExp(text, 'gi'), numbers.join());
|
||||
}
|
||||
|
||||
function convertRange(expression){
|
||||
var rangeRegEx = /(\d+)\-(\d+)/;
|
||||
var match = rangeRegEx.exec(expression);
|
||||
while(match !== null && match.length > 0){
|
||||
expression = replaceWithRange(expression, match[0], match[1], match[2]);
|
||||
match = rangeRegEx.exec(expression);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
function convertAllRanges(expressions){
|
||||
for(var i = 0; i < expressions.length; i++){
|
||||
expressions[i] = convertRange(expressions[i]);
|
||||
}
|
||||
return expressions;
|
||||
}
|
||||
|
||||
return convertAllRanges;
|
||||
})();
|
||||
|
||||
|
||||
|
||||
27
node_modules/node-cron/src/convert-expression/step-values-conversion.js
generated
vendored
Normal file
27
node_modules/node-cron/src/convert-expression/step-values-conversion.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (() => {
|
||||
function convertSteps(expressions){
|
||||
var stepValuePattern = /^(.+)\/(\d+)$/;
|
||||
for(var i = 0; i < expressions.length; i++){
|
||||
var match = stepValuePattern.exec(expressions[i]);
|
||||
var isStepValue = match !== null && match.length > 0;
|
||||
if(isStepValue){
|
||||
var values = match[1].split(',');
|
||||
var setpValues = [];
|
||||
var divider = parseInt(match[2], 10);
|
||||
for(var j = 0; j <= values.length; j++){
|
||||
var value = parseInt(values[j], 10);
|
||||
if(value % divider === 0){
|
||||
setpValues.push(value);
|
||||
}
|
||||
}
|
||||
expressions[i] = setpValues.join(',');
|
||||
}
|
||||
}
|
||||
return expressions;
|
||||
}
|
||||
|
||||
return convertSteps;
|
||||
})();
|
||||
|
||||
21
node_modules/node-cron/src/convert-expression/week-day-names-conversion.js
generated
vendored
Normal file
21
node_modules/node-cron/src/convert-expression/week-day-names-conversion.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
module.exports = (() => {
|
||||
var weekDays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
|
||||
'friday', 'saturday'];
|
||||
var shortWeekDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
||||
|
||||
function convertWeekDayName(expression, items){
|
||||
for(var i = 0; i < items.length; i++){
|
||||
expression = expression.replace(new RegExp(items[i], 'gi'), parseInt(i, 10));
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
function convertWeekDays(expression){
|
||||
expression = expression.replace('7', '0');
|
||||
expression = convertWeekDayName(expression, weekDays);
|
||||
return convertWeekDayName(expression, shortWeekDays);
|
||||
}
|
||||
|
||||
return convertWeekDays;
|
||||
})();
|
||||
61
node_modules/node-cron/src/node-cron.js
generated
vendored
Normal file
61
node_modules/node-cron/src/node-cron.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
var Task = require('./task'),
|
||||
ScheduledTask = require('./scheduled-task'),
|
||||
validation = require('./pattern-validation');
|
||||
|
||||
module.exports = (() => {
|
||||
|
||||
/**
|
||||
* Creates a new task to execute given function when the cron
|
||||
* expression ticks.
|
||||
*
|
||||
* @param {string} expression - cron expression.
|
||||
* @param {Function} func - task to be executed.
|
||||
* @param {Object} options - a set of options for the scheduled task:
|
||||
* - scheduled <boolean>: if a schaduled task is ready and running to be
|
||||
* performed when the time mach with the cron excpression.
|
||||
* - timezone <string>: the tiemzone to execute the tasks.
|
||||
*
|
||||
* Example:
|
||||
* {
|
||||
* "scheduled": true,
|
||||
* "timezone": "America/Sao_Paulo"
|
||||
* }
|
||||
*
|
||||
* @returns {ScheduledTask} update function.
|
||||
*/
|
||||
function createTask(expression, func, options) {
|
||||
// Added for immediateStart depreciation
|
||||
if(typeof options === 'boolean'){
|
||||
console.warn('DEPRECIATION: imediateStart is deprecated and will be removed soon in favor of the options param.');
|
||||
options = {
|
||||
scheduled: options
|
||||
};
|
||||
}
|
||||
|
||||
if(!options){
|
||||
options = {
|
||||
scheduled: true
|
||||
};
|
||||
}
|
||||
|
||||
var task = new Task(expression, func);
|
||||
return new ScheduledTask(task, options);
|
||||
}
|
||||
|
||||
function validate(expression) {
|
||||
try {
|
||||
validation(expression);
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
schedule: createTask,
|
||||
validate: validate
|
||||
};
|
||||
})();
|
||||
87
node_modules/node-cron/src/pattern-validation.js
generated
vendored
Normal file
87
node_modules/node-cron/src/pattern-validation.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
var convertExpression = require('./convert-expression');
|
||||
|
||||
|
||||
module.exports = ( () => {
|
||||
function isValidExpression(expression, min, max){
|
||||
var options = expression.split(',');
|
||||
var regexValidation = /^\d+$|^\*$|^\*\/\d+$/;
|
||||
for(var i = 0; i < options.length; i++){
|
||||
var option = options[i];
|
||||
var optionAsInt = parseInt(options[i], 10);
|
||||
if(optionAsInt < min || optionAsInt > max || !regexValidation.test(option)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isInvalidSecond(expression){
|
||||
return !isValidExpression(expression, 0, 59);
|
||||
}
|
||||
|
||||
function isInvalidMinute(expression){
|
||||
return !isValidExpression(expression, 0, 59);
|
||||
}
|
||||
|
||||
function isInvalidHour(expression){
|
||||
return !isValidExpression(expression, 0, 23);
|
||||
}
|
||||
|
||||
function isInvalidDayOfMonth(expression){
|
||||
return !isValidExpression(expression, 1, 31);
|
||||
}
|
||||
|
||||
function isInvalidMonth(expression){
|
||||
return !isValidExpression(expression, 1, 12);
|
||||
}
|
||||
|
||||
function isInvalidWeekDay(expression){
|
||||
return !isValidExpression(expression, 0, 7);
|
||||
}
|
||||
|
||||
function validateFields(patterns, executablePatterns){
|
||||
if (isInvalidSecond(executablePatterns[0])) {
|
||||
throw patterns[0] + ' is a invalid expression for second';
|
||||
}
|
||||
|
||||
if (isInvalidMinute(executablePatterns[1])) {
|
||||
throw patterns[1] + ' is a invalid expression for minute';
|
||||
}
|
||||
|
||||
if (isInvalidHour(executablePatterns[2])) {
|
||||
throw patterns[2] + ' is a invalid expression for hour';
|
||||
}
|
||||
|
||||
if (isInvalidDayOfMonth(executablePatterns[3])) {
|
||||
throw patterns[3] + ' is a invalid expression for day of month';
|
||||
}
|
||||
|
||||
if (isInvalidMonth(executablePatterns[4])) {
|
||||
throw patterns[4] + ' is a invalid expression for month';
|
||||
}
|
||||
|
||||
if (isInvalidWeekDay(executablePatterns[5])) {
|
||||
throw patterns[5] + ' is a invalid expression for week day';
|
||||
}
|
||||
}
|
||||
|
||||
function validate(pattern){
|
||||
if (typeof pattern !== 'string'){
|
||||
throw 'pattern must be a string!';
|
||||
}
|
||||
|
||||
var patterns = pattern.split(' ');
|
||||
var executablePattern = convertExpression(pattern);
|
||||
var executablePatterns = executablePattern.split(' ');
|
||||
|
||||
if(patterns.length === 5){
|
||||
patterns = ['0'].concat(patterns);
|
||||
}
|
||||
|
||||
validateFields(patterns, executablePatterns);
|
||||
}
|
||||
|
||||
return validate;
|
||||
})();
|
||||
96
node_modules/node-cron/src/scheduled-task.js
generated
vendored
Normal file
96
node_modules/node-cron/src/scheduled-task.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
'use strict';
|
||||
|
||||
var tzOffset = require('tz-offset');
|
||||
|
||||
/**
|
||||
* Creates a new scheduled task.
|
||||
*
|
||||
* @param {Task} task - task to schedule.
|
||||
* @param {*} options - task options.
|
||||
*/
|
||||
function ScheduledTask(task, options) {
|
||||
var timezone = options.timezone;
|
||||
|
||||
/**
|
||||
* Starts updating the task.
|
||||
*
|
||||
* @returns {ScheduledTask} instance of this task.
|
||||
*/
|
||||
this.start = () => {
|
||||
this.status = 'scheduled';
|
||||
if (this.task && !this.tick) {
|
||||
this.tick = setTimeout(this.task, 1000 - new Date().getMilliseconds() + 1);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops updating the task.
|
||||
*
|
||||
* @returns {ScheduledTask} instance of this task.
|
||||
*/
|
||||
this.stop = () => {
|
||||
this.status = 'stoped';
|
||||
if (this.tick) {
|
||||
clearTimeout(this.tick);
|
||||
this.tick = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current task status.
|
||||
*
|
||||
* @returns {string} current task status.
|
||||
* The return may be:
|
||||
* - scheduled: when a task is scheduled and waiting to be executed.
|
||||
* - running: the task status while the task is executing.
|
||||
* - stoped: when the task is stoped.
|
||||
* - destroyed: whe the task is destroyed, in that status the task cannot be re-started.
|
||||
* - failed: a task is maker as failed when the previous execution fails.
|
||||
*/
|
||||
this.getStatus = () => {
|
||||
return this.status;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys the scheduled task.
|
||||
*/
|
||||
this.destroy = () => {
|
||||
this.stop();
|
||||
this.status = 'destroyed';
|
||||
|
||||
this.task = null;
|
||||
};
|
||||
|
||||
task.on('started', () => {
|
||||
this.status = 'running';
|
||||
});
|
||||
|
||||
task.on('done', () => {
|
||||
this.status = 'scheduled';
|
||||
});
|
||||
|
||||
task.on('failed', () => {
|
||||
this.status = 'failed';
|
||||
});
|
||||
|
||||
this.task = () => {
|
||||
var date = new Date();
|
||||
if(timezone){
|
||||
date = tzOffset.timeAt(date, timezone);
|
||||
}
|
||||
this.tick = setTimeout(this.task, 1000 - date.getMilliseconds() + 1);
|
||||
task.update(date);
|
||||
};
|
||||
|
||||
this.tick = null;
|
||||
|
||||
if (options.scheduled !== false) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ScheduledTask;
|
||||
70
node_modules/node-cron/src/task.js
generated
vendored
Normal file
70
node_modules/node-cron/src/task.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var convertExpression = require('./convert-expression');
|
||||
var validatePattern = require('./pattern-validation');
|
||||
|
||||
var events = require('events');
|
||||
|
||||
|
||||
function matchPattern(pattern, value){
|
||||
if( pattern.indexOf(',') !== -1 ){
|
||||
var patterns = pattern.split(',');
|
||||
return patterns.indexOf(value.toString()) !== -1;
|
||||
}
|
||||
return pattern === value.toString();
|
||||
}
|
||||
|
||||
function mustRun(task, date){
|
||||
var runInSecond = matchPattern(task.expressions[0], date.getSeconds());
|
||||
var runOnMinute = matchPattern(task.expressions[1], date.getMinutes());
|
||||
var runOnHour = matchPattern(task.expressions[2], date.getHours());
|
||||
var runOnDayOfMonth = matchPattern(task.expressions[3], date.getDate());
|
||||
var runOnMonth = matchPattern(task.expressions[4], date.getMonth() + 1);
|
||||
var runOnDayOfWeek = matchPattern(task.expressions[5], date.getDay());
|
||||
|
||||
var runOnDay = false;
|
||||
var delta = task.initialPattern.length === 6 ? 0 : -1;
|
||||
|
||||
if (task.initialPattern[3 + delta] === '*') {
|
||||
runOnDay = runOnDayOfWeek;
|
||||
} else if (task.initialPattern[5 + delta] === '*') {
|
||||
runOnDay = runOnDayOfMonth;
|
||||
} else {
|
||||
runOnDay = runOnDayOfMonth || runOnDayOfWeek;
|
||||
}
|
||||
|
||||
return runInSecond && runOnMinute && runOnHour && runOnDay && runOnMonth;
|
||||
}
|
||||
|
||||
function Task(pattern, execution){
|
||||
validatePattern(pattern);
|
||||
this.initialPattern = pattern.split(' ');
|
||||
this.pattern = convertExpression(pattern);
|
||||
this.execution = execution;
|
||||
this.expressions = this.pattern.split(' ');
|
||||
|
||||
events.EventEmitter.call(this);
|
||||
|
||||
this.update = (date) => {
|
||||
if(mustRun(this, date)){
|
||||
new Promise((resolve, reject) => {
|
||||
this.emit('started', this);
|
||||
var ex = this.execution();
|
||||
if(ex instanceof Promise){
|
||||
ex.then(resolve).catch(reject);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
}).then(() => {
|
||||
this.emit('done', this);
|
||||
}).catch((error) => {
|
||||
console.error(error);
|
||||
this.emit('failed', error);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Task.prototype = events.EventEmitter.prototype;
|
||||
module.exports = Task;
|
||||
|
||||
12
node_modules/node-cron/test/convert-expression/asterisk-to-range-conversion-test.js
generated
vendored
Normal file
12
node_modules/node-cron/test/convert-expression/asterisk-to-range-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var conversion = require('../../src/convert-expression/asterisk-to-range-conversion');
|
||||
|
||||
describe('asterisk-to-range-conversion.js', () => {
|
||||
it('shuld convert * to ranges', () => {
|
||||
var expressions = '* * * * * *'.split(' ');
|
||||
var expression = conversion(expressions).join(' ');
|
||||
expect(expression).to.equal('0-59 0-59 0-23 1-31 1-12 0-6');
|
||||
});
|
||||
});
|
||||
18
node_modules/node-cron/test/convert-expression/convert-expression-test.js
generated
vendored
Normal file
18
node_modules/node-cron/test/convert-expression/convert-expression-test.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var conversion = require('../../src/convert-expression');
|
||||
|
||||
describe('month-names-conversion.js', () => {
|
||||
it('shuld convert month names', () => {
|
||||
var expression = conversion('* * * * January,February *');
|
||||
var expressions = expression.split(' ');
|
||||
expect(expressions[4]).to.equal('1,2');
|
||||
});
|
||||
|
||||
it('shuld convert week day names', () => {
|
||||
var expression = conversion('* * * * * Mon,Sun');
|
||||
var expressions = expression.split(' ');
|
||||
expect(expressions[5]).to.equal('1,0');
|
||||
});
|
||||
});
|
||||
16
node_modules/node-cron/test/convert-expression/month-names-conversion-test.js
generated
vendored
Normal file
16
node_modules/node-cron/test/convert-expression/month-names-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var conversion = require('../../src/convert-expression/month-names-conversion');
|
||||
|
||||
describe('month-names-conversion.js', () => {
|
||||
it('shuld convert month names', () => {
|
||||
var months = conversion('January,February,March,April,May,June,July,August,September,October,November,December');
|
||||
expect(months).to.equal('1,2,3,4,5,6,7,8,9,10,11,12');
|
||||
});
|
||||
|
||||
it('shuld convert month names', () => {
|
||||
var months = conversion('Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec');
|
||||
expect(months).to.equal('1,2,3,4,5,6,7,8,9,10,11,12');
|
||||
});
|
||||
});
|
||||
18
node_modules/node-cron/test/convert-expression/range-conversion-test.js
generated
vendored
Normal file
18
node_modules/node-cron/test/convert-expression/range-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var conversion = require('../../src/convert-expression/range-conversion');
|
||||
|
||||
describe('range-conversion.js', () => {
|
||||
it('shuld convert ranges to numbers', () => {
|
||||
var expressions = '0-3 0-3 0-2 1-3 1-2 0-3'.split(' ');
|
||||
var expression = conversion(expressions).join(' ');
|
||||
expect(expression).to.equal('0,1,2,3 0,1,2,3 0,1,2 1,2,3 1,2 0,1,2,3');
|
||||
});
|
||||
|
||||
it('shuld convert ranges to numbers', () => {
|
||||
var expressions = '0-3 0-3 8-10 1-3 1-2 0-3'.split(' ');
|
||||
var expression = conversion(expressions).join(' ');
|
||||
expect(expression).to.equal('0,1,2,3 0,1,2,3 8,9,10 1,2,3 1,2 0,1,2,3');
|
||||
});
|
||||
});
|
||||
14
node_modules/node-cron/test/convert-expression/step-values-conversion-test.js
generated
vendored
Normal file
14
node_modules/node-cron/test/convert-expression/step-values-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var conversion = require('../../src/convert-expression/step-values-conversion');
|
||||
|
||||
describe('step-values-conversion.js', () => {
|
||||
it('shuld convert step values', () => {
|
||||
var expressions = '1,2,3,4,5,6,7,8,9,10/2 0,1,2,3,4,5,6,7,8,9/5 * * * *'.split(' ');
|
||||
expressions = conversion(expressions);
|
||||
console.log(expressions);
|
||||
expect(expressions[0]).to.equal('2,4,6,8,10');
|
||||
expect(expressions[1]).to.equal('0,5');
|
||||
});
|
||||
});
|
||||
21
node_modules/node-cron/test/convert-expression/week-day-names-conversion-test.js
generated
vendored
Normal file
21
node_modules/node-cron/test/convert-expression/week-day-names-conversion-test.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var conversion = require('../../src/convert-expression/week-day-names-conversion');
|
||||
|
||||
describe('week-day-names-conversion.js', () => {
|
||||
it('shuld convert week day names names', () => {
|
||||
var weekDays = conversion('Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday');
|
||||
expect(weekDays).to.equal('1,2,3,4,5,6,0');
|
||||
});
|
||||
|
||||
it('shuld convert short week day names names', () => {
|
||||
var weekDays = conversion('Mon,Tue,Wed,Thu,Fri,Sat,Sun');
|
||||
expect(weekDays).to.equal('1,2,3,4,5,6,0');
|
||||
});
|
||||
|
||||
it('shuld convert 7 to 0', () => {
|
||||
var weekDays = conversion('7');
|
||||
expect(weekDays).to.equal('0');
|
||||
});
|
||||
});
|
||||
27
node_modules/node-cron/test/defer-start-test.js
generated
vendored
Normal file
27
node_modules/node-cron/test/defer-start-test.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('defer a task', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should defer start of a task', () => {
|
||||
var executed = 0,
|
||||
task = cron.schedule('* * * * *', () => {
|
||||
executed++;
|
||||
}, false);
|
||||
|
||||
this.clock.tick(1000 * 60);
|
||||
task.start();
|
||||
this.clock.tick(1001 * 60);
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
});
|
||||
30
node_modules/node-cron/test/destroy-task-test.js
generated
vendored
Normal file
30
node_modules/node-cron/test/destroy-task-test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('destroying a task', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should destroy the task', () => {
|
||||
var executed = 0,
|
||||
task = cron.schedule('* * * * *', () => {
|
||||
executed++;
|
||||
});
|
||||
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
task.destroy();
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
task.start();
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
});
|
||||
37
node_modules/node-cron/test/multiples-values-test.js
generated
vendored
Normal file
37
node_modules/node-cron/test/multiples-values-test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('scheduling with multiples values', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should accept multiples values in minute', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
var executed = 0;
|
||||
cron.schedule('2,3,4 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(7000 * 60);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
|
||||
it('should accept multiples values in hour', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
var executed = 0;
|
||||
cron.schedule('2,3,4 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(7000 * 60);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
});
|
||||
34
node_modules/node-cron/test/pattern-validation/validate-day-test.js
generated
vendored
Normal file
34
node_modules/node-cron/test/pattern-validation/validate-day-test.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate day of month', () => {
|
||||
it('should fail with invalid day of month', () => {
|
||||
expect(() => {
|
||||
validate('* * 32 * *');
|
||||
}).to.throwException((e) =>{
|
||||
expect('32 is a invalid expression for day of month').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail with valid day of month', () => {
|
||||
expect(() => {
|
||||
validate('0 * * 15 * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with * for day of month', () => {
|
||||
expect(() => {
|
||||
validate('* * * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for day of month', () => {
|
||||
expect(() => {
|
||||
validate('* * */2 * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
40
node_modules/node-cron/test/pattern-validation/validate-hours-test.js
generated
vendored
Normal file
40
node_modules/node-cron/test/pattern-validation/validate-hours-test.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate hour', () => {
|
||||
it('should fail with invalid hour', () => {
|
||||
expect(() => {
|
||||
validate('* 25 * * *');
|
||||
}).to.throwException((e) => {
|
||||
expect('25 is a invalid expression for hour').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail with valid hour', () => {
|
||||
expect(() => {
|
||||
validate('* 12 * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with * for hour', () => {
|
||||
expect(() => {
|
||||
validate('* * * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for hour', () => {
|
||||
expect(() => {
|
||||
validate('* */2 * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should accept range for hours', () => {
|
||||
expect(() => {
|
||||
validate('* 3-20 * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
34
node_modules/node-cron/test/pattern-validation/validate-minute-test.js
generated
vendored
Normal file
34
node_modules/node-cron/test/pattern-validation/validate-minute-test.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate minutes', () => {
|
||||
it('should fail with invalid minute', () => {
|
||||
expect(() => {
|
||||
validate('63 * * * *');
|
||||
}).to.throwException((e) => {
|
||||
expect('63 is a invalid expression for minute').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail with valid minute', () => {
|
||||
expect(() => {
|
||||
validate('30 * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with *', () => {
|
||||
expect(() => {
|
||||
validate('* * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with */2', () => {
|
||||
expect(() => {
|
||||
validate('*/2 * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
48
node_modules/node-cron/test/pattern-validation/validate-month-test.js
generated
vendored
Normal file
48
node_modules/node-cron/test/pattern-validation/validate-month-test.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate month', () => {
|
||||
it('should fail with invalid month', () => {
|
||||
expect( () => {
|
||||
validate('* * * 13 *');
|
||||
}).to.throwException((e) => {
|
||||
expect('13 is a invalid expression for month').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail with invalid month name', () => {
|
||||
expect( () => {
|
||||
validate('* * * foo *');
|
||||
}).to.throwException(function(e){
|
||||
expect('foo is a invalid expression for month').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail with valid month', () => {
|
||||
expect( () => {
|
||||
validate('* * * 10 *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with valid month name', () => {
|
||||
expect( () => {
|
||||
validate('* * * September *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with * for month', () => {
|
||||
expect( () => {
|
||||
validate('* * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for month', () => {
|
||||
expect( () => {
|
||||
validate('* * * */2 *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
21
node_modules/node-cron/test/pattern-validation/validate-pattern-type.js
generated
vendored
Normal file
21
node_modules/node-cron/test/pattern-validation/validate-pattern-type.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
it('should accept string for pattern', () => {
|
||||
expect(() => {
|
||||
new Task('* * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should fail with a non string value for pattern', () => {
|
||||
expect(() => {
|
||||
new Task([]);
|
||||
}).to.throwException((e) => {
|
||||
expect('pattern must be a string!').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
34
node_modules/node-cron/test/pattern-validation/validate-second-test.js
generated
vendored
Normal file
34
node_modules/node-cron/test/pattern-validation/validate-second-test.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate seconds', () => {
|
||||
it('should fail with invalid second', () => {
|
||||
expect(() => {
|
||||
validate('63 * * * * *');
|
||||
}).to.throwException((e) => {
|
||||
expect('63 is a invalid expression for second').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail with valid second', () => {
|
||||
expect(() => {
|
||||
validate('30 * * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with * for second', () => {
|
||||
expect(() => {
|
||||
validate('* * * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for second', () => {
|
||||
expect(() => {
|
||||
validate('*/2 * * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
16
node_modules/node-cron/test/pattern-validation/validate-test.js
generated
vendored
Normal file
16
node_modules/node-cron/test/pattern-validation/validate-test.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var cron = require('../../src/node-cron');
|
||||
|
||||
describe('public .validate() method', () => {
|
||||
it('should succeed with a valid expression', () => {
|
||||
var result = cron.validate('59 * * * *');
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
|
||||
it('should fail with an invalid expression', () => {
|
||||
var result = cron.validate('60 * * * *');
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
});
|
||||
60
node_modules/node-cron/test/pattern-validation/validate-week-day-test.js
generated
vendored
Normal file
60
node_modules/node-cron/test/pattern-validation/validate-week-day-test.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var validate = require('../../src/pattern-validation');
|
||||
|
||||
describe('pattern-validation.js', () => {
|
||||
describe('validate week day', () => {
|
||||
it('should fail with invalid week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * 9');
|
||||
}).to.throwException((e) => {
|
||||
expect('9 is a invalid expression for week day').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail with invalid week day name', () => {
|
||||
expect(() => {
|
||||
validate('* * * * foo');
|
||||
}).to.throwException((e) => {
|
||||
expect('foo is a invalid expression for week day').to.equal(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail with valid week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * 5');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with valid week day name', () => {
|
||||
expect(() => {
|
||||
validate('* * * * Friday');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with * for week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with */2 for week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * */2 *');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with Monday-Sunday for week day', () => {
|
||||
expect(() => {
|
||||
validate('* * * * Monday-Sunday');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
it('should not fail with 1-7 for week day', () => {
|
||||
expect(() => {
|
||||
validate('0 0 1 1 1-7');
|
||||
}).to.not.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
37
node_modules/node-cron/test/range-values-test.js
generated
vendored
Normal file
37
node_modules/node-cron/test/range-values-test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('scheduling with range values', () =>{
|
||||
beforeEach(() =>{
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() =>{
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should accept range values in minute', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
var executed = 0;
|
||||
cron.schedule('2-4 * * * *', () =>{
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(7001 * 60);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
|
||||
it('should accept range values in hour', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
var executed = 0;
|
||||
cron.schedule('0 2-4 * * *', () =>{
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(7001 * 60 * 60);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
});
|
||||
30
node_modules/node-cron/test/restart-task-test.js
generated
vendored
Normal file
30
node_modules/node-cron/test/restart-task-test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('restarting a task', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should restart a task', () => {
|
||||
var executed = 0,
|
||||
task = cron.schedule('* * * * *', () => {
|
||||
executed++;
|
||||
});
|
||||
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
task.stop();
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
task.start();
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
|
||||
expect(executed).to.equal(2);
|
||||
});
|
||||
});
|
||||
74
node_modules/node-cron/test/scheduled-taks-test.js
generated
vendored
Normal file
74
node_modules/node-cron/test/scheduled-taks-test.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var ScheduledTask = require('../src/scheduled-task');
|
||||
var Task = require('../src/task');
|
||||
|
||||
describe('ScheduledTask', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() =>{
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should return scheduled status', () => {
|
||||
var task = new Task('* * * * *');
|
||||
var scheduledTask = new ScheduledTask(task, {});
|
||||
expect(scheduledTask.getStatus()).to.equal('scheduled');
|
||||
});
|
||||
|
||||
it('should return running status', (done) => {
|
||||
var task = new Task('* * * * * *', () =>{});
|
||||
var scheduledTask = new ScheduledTask(task, {});
|
||||
|
||||
task.on('started', () => {
|
||||
expect(scheduledTask.getStatus()).to.equal('running');
|
||||
done();
|
||||
});
|
||||
|
||||
this.clock.tick(1100);
|
||||
});
|
||||
|
||||
it('should return stoped status', () => {
|
||||
var task = new Task('* * * * *');
|
||||
var scheduledTask = new ScheduledTask(task, {});
|
||||
scheduledTask.stop();
|
||||
expect(scheduledTask.getStatus()).to.equal('stoped');
|
||||
});
|
||||
|
||||
it('should return destroyed status', () => {
|
||||
var task = new Task('* * * * *');
|
||||
var scheduledTask = new ScheduledTask(task, {});
|
||||
scheduledTask.destroy();
|
||||
expect(scheduledTask.getStatus()).to.equal('destroyed');
|
||||
});
|
||||
|
||||
it('should return scheduled status after execution', (done) => {
|
||||
var task = new Task('* * * * * *', () =>{});
|
||||
var scheduledTask = new ScheduledTask(task, {});
|
||||
|
||||
task.on('done', () => {
|
||||
expect(scheduledTask.getStatus()).to.equal('scheduled');
|
||||
done();
|
||||
});
|
||||
|
||||
this.clock.tick(1100);
|
||||
});
|
||||
|
||||
it('should return failed status after task error', (done) => {
|
||||
var task = new Task('* * * * * *', () => {
|
||||
throw 'Error';
|
||||
});
|
||||
var scheduledTask = new ScheduledTask(task, {});
|
||||
|
||||
task.on('failed', () => {
|
||||
expect(scheduledTask.getStatus()).to.equal('failed');
|
||||
done();
|
||||
});
|
||||
|
||||
this.clock.tick(1100);
|
||||
});
|
||||
});
|
||||
120
node_modules/node-cron/test/scheduling-test.js
generated
vendored
Normal file
120
node_modules/node-cron/test/scheduling-test.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('scheduling on minutes', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should execute a task every minute', () => {
|
||||
var executed = 0;
|
||||
cron.schedule('* * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(3000 * 60 + 1);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
|
||||
it('should execute a task on minute 1', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('1 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(3000 * 60);
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
|
||||
it('should execute a task on minutes multiples of 5', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('*/5 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(1000 * 60 * 23);
|
||||
expect(executed).to.equal(4);
|
||||
});
|
||||
|
||||
it('should execute a task every minute from 10 to 20', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('10-20 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(1000 * 60 * 30);
|
||||
expect(executed).to.equal(11);
|
||||
});
|
||||
|
||||
it('should execute a task every minute from 10 to 20 and from 30 to 35', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('10-20,30-35 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(1000 * 60 * 40);
|
||||
expect(executed).to.equal(17);
|
||||
});
|
||||
|
||||
it('should allows lead zeros', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('01 * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(2000);
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
|
||||
it('should allows lead zeros range', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('01-05 * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(6000);
|
||||
expect(executed).to.equal(5);
|
||||
});
|
||||
|
||||
it('should allows lead zeros step', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
this.clock = sinon.useFakeTimers(initialDate.getTime());
|
||||
var executed = 0;
|
||||
cron.schedule('*/02 * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(6001);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
|
||||
it('should schedule a task that returns a promise', () => {
|
||||
let executed = 0;
|
||||
cron.schedule('* * * * * *', () => {
|
||||
return new Promise((resolve) => {
|
||||
executed += 1;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
this.clock.tick(1001);
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
});
|
||||
38
node_modules/node-cron/test/step-value-test.js
generated
vendored
Normal file
38
node_modules/node-cron/test/step-value-test.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('scheduling with divided values', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should accept * divided by 2 for minutes', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
var executed = 0;
|
||||
cron.schedule('*/2 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(5000 * 60);
|
||||
expect(executed).to.equal(2);
|
||||
});
|
||||
|
||||
it('should accept 0-10 divided by 2 for minutes', () => {
|
||||
var initialDate = new Date();
|
||||
initialDate.setMinutes(0);
|
||||
var executed = 0;
|
||||
cron.schedule('0-10/2 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
this.clock.tick(15000 * 60);
|
||||
expect(executed).to.equal(5);
|
||||
});
|
||||
|
||||
});
|
||||
27
node_modules/node-cron/test/stop-task-test.js
generated
vendored
Normal file
27
node_modules/node-cron/test/stop-task-test.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('stopping a task', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should stop a task', () => {
|
||||
var executed = 0,
|
||||
task = cron.schedule('* * * * *', () => {
|
||||
executed++;
|
||||
});
|
||||
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
task.stop();
|
||||
this.clock.tick(1000 * 60 + 1);
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
});
|
||||
76
node_modules/node-cron/test/task/task-day-of-month-test.js
generated
vendored
Normal file
76
node_modules/node-cron/test/task/task-day-of-month-test.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('day of day', () => {
|
||||
it('should run on day', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setDate(0);
|
||||
task.update(date);
|
||||
date.setDate(15);
|
||||
task.update(date);
|
||||
date.setDate(50);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on day 9', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * 9 * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
executed = 0;
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setDate(3);
|
||||
task.update(date);
|
||||
date.setDate(9);
|
||||
task.update(date);
|
||||
date.setDate(11);
|
||||
task.update(date);
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on day 4, 6 and 12 ', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * 4,6,12 * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
executed = 0;
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setDate(1);
|
||||
task.update(date);
|
||||
date.setDate(4);
|
||||
task.update(date);
|
||||
date.setDate(6);
|
||||
task.update(date);
|
||||
date.setDate(8);
|
||||
task.update(date);
|
||||
date.setDate(12);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run in even day', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * */2 * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
executed = 0;
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setDate(2);
|
||||
task.update(date);
|
||||
date.setDate(15);
|
||||
task.update(date);
|
||||
date.setDate(20);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
25
node_modules/node-cron/test/task/task-fail-test.js
generated
vendored
Normal file
25
node_modules/node-cron/test/task/task-fail-test.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../../src/node-cron');
|
||||
|
||||
describe('scheduling a task with exception', () =>{
|
||||
beforeEach(() =>{
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() =>{
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should not stop on task exception', () => {
|
||||
var executed = 0;
|
||||
cron.schedule('* * * * *', () =>{
|
||||
executed += 1;
|
||||
throw 'exception!';
|
||||
});
|
||||
this.clock.tick(3000 * 60 + 1);
|
||||
expect(executed).to.equal(3);
|
||||
});
|
||||
});
|
||||
90
node_modules/node-cron/test/task/task-hour-test.js
generated
vendored
Normal file
90
node_modules/node-cron/test/task/task-hour-test.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('hour', () => {
|
||||
it('should run a task on hour', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setHours(0);
|
||||
task.update(date);
|
||||
date.setHours(15);
|
||||
task.update(date);
|
||||
date.setHours(50);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on hour 12', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('0 12 * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setHours(3);
|
||||
task.update(date);
|
||||
date.setHours(12);
|
||||
task.update(date);
|
||||
date.setHours(15);
|
||||
task.update(date);
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on hours 20, 30 and 40 ', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('0 5,10,20 * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setHours(5);
|
||||
task.update(date);
|
||||
date.setHours(10);
|
||||
task.update(date);
|
||||
date.setHours(13);
|
||||
task.update(date);
|
||||
date.setHours(20);
|
||||
task.update(date);
|
||||
date.setHours(22);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run in even hours', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* */2 * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setHours(0);
|
||||
task.update(date);
|
||||
date.setHours(15);
|
||||
task.update(date);
|
||||
date.setHours(50);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run every hour on range', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* 8-20 * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setHours(0);
|
||||
task.update(date);
|
||||
date.setHours(8);
|
||||
task.update(date);
|
||||
date.setHours(19);
|
||||
task.update(date);
|
||||
date.setHours(21);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
73
node_modules/node-cron/test/task/task-minute-test.js
generated
vendored
Normal file
73
node_modules/node-cron/test/task/task-minute-test.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('minute', () => {
|
||||
it('should run a task on minute', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMinutes(0);
|
||||
task.update(date);
|
||||
date.setMinutes(15);
|
||||
task.update(date);
|
||||
date.setMinutes(50);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on minute 33', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('33 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMinutes(3);
|
||||
task.update(date);
|
||||
date.setMinutes(33);
|
||||
task.update(date);
|
||||
date.setMinutes(32);
|
||||
task.update(date);
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on minutes 20, 30 and 40 ', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('20,30,40 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMinutes(20);
|
||||
task.update(date);
|
||||
date.setMinutes(30);
|
||||
task.update(date);
|
||||
date.setMinutes(33);
|
||||
task.update(date);
|
||||
date.setMinutes(40);
|
||||
task.update(date);
|
||||
date.setMinutes(50);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run in even minutes', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('*/2 * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMinutes(0);
|
||||
task.update(date);
|
||||
date.setMinutes(15);
|
||||
task.update(date);
|
||||
date.setMinutes(50);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
82
node_modules/node-cron/test/task/task-month-test.js
generated
vendored
Normal file
82
node_modules/node-cron/test/task/task-month-test.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('month', () => {
|
||||
it('should run a task on month', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMonth(0);
|
||||
task.update(date);
|
||||
date.setMonth(10);
|
||||
task.update(date);
|
||||
date.setMonth(12);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on month 9', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * 9 *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 3, 1);
|
||||
date.setMonth(3);
|
||||
task.update(date);
|
||||
date.setMonth(8);
|
||||
task.update(date);
|
||||
date.setMonth(10);
|
||||
task.update(date);
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on months 2, 4 and 6 ', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * 2,4,6 *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMonth(0);
|
||||
task.update(date);
|
||||
date.setMonth(1);
|
||||
task.update(date);
|
||||
date.setMonth(3);
|
||||
task.update(date);
|
||||
date.setMonth(5);
|
||||
task.update(date);
|
||||
date.setMonth(7);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run in even months', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * */2 *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setMonth(1);
|
||||
task.update(date);
|
||||
date.setMonth(9);
|
||||
task.update(date);
|
||||
date.setMonth(8);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on September', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * Sep *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
task.update(new Date(2016, 8, 1));
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
73
node_modules/node-cron/test/task/task-second-test.js
generated
vendored
Normal file
73
node_modules/node-cron/test/task/task-second-test.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('second', () => {
|
||||
it('should run a task on second', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setSeconds(0);
|
||||
task.update(date);
|
||||
date.setSeconds(15);
|
||||
task.update(date);
|
||||
date.setSeconds(50);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on second 33', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('33 * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setSeconds(3);
|
||||
task.update(date);
|
||||
date.setSeconds(33);
|
||||
task.update(date);
|
||||
date.setSeconds(32);
|
||||
task.update(date);
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on seconds 20, 30 and 40 ', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('20,30,40 * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setSeconds(20);
|
||||
task.update(date);
|
||||
date.setSeconds(30);
|
||||
task.update(date);
|
||||
date.setSeconds(33);
|
||||
task.update(date);
|
||||
date.setSeconds(40);
|
||||
task.update(date);
|
||||
date.setSeconds(50);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run in even seconds', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('*/2 * * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 1, 1);
|
||||
date.setSeconds(0);
|
||||
task.update(date);
|
||||
date.setSeconds(15);
|
||||
task.update(date);
|
||||
date.setSeconds(50);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
89
node_modules/node-cron/test/task/task-week-day-day-of-month-test.js
generated
vendored
Normal file
89
node_modules/node-cron/test/task/task-week-day-day-of-month-test.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('week day & day of month', () => {
|
||||
|
||||
it('should run on week day', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * 1', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
for (var day = 1; day <= 7; day++) {
|
||||
date.setDate(day);
|
||||
task.update(date);
|
||||
}
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on day of month', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * 1 * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
for (var day = 1; day <= 7; day++) {
|
||||
date.setDate(day);
|
||||
task.update(date);
|
||||
}
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on week day & day of month', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * 1 * 1', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
for (var day = 1; day <= 7; day++) {
|
||||
date.setDate(day);
|
||||
task.update(date);
|
||||
}
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on week day with seconds', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('0 * * * * 1', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
for (var day = 1; day <= 7; day++) {
|
||||
date.setDate(day);
|
||||
task.update(date);
|
||||
}
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on day of month with seconds', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('0 * * 1 * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
for (var day = 1; day <= 7; day++) {
|
||||
date.setDate(day);
|
||||
task.update(date);
|
||||
}
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on week day & day of month with seconds', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('0 * * 1 * 1', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
for (var day = 1; day <= 7; day++) {
|
||||
date.setDate(day);
|
||||
task.update(date);
|
||||
}
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
82
node_modules/node-cron/test/task/task-week-day-test.js
generated
vendored
Normal file
82
node_modules/node-cron/test/task/task-week-day-test.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Task = require('../../src/task');
|
||||
|
||||
describe('Task', () => {
|
||||
describe('week day', () => {
|
||||
it('should run on week day', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * *', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
date.setDate(4);
|
||||
task.update(date);
|
||||
date.setDate(5);
|
||||
task.update(date);
|
||||
date.setDate(6);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on week day 3', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * 3', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
date.setDate(5);
|
||||
task.update(date);
|
||||
date.setDate(6);
|
||||
task.update(date);
|
||||
date.setDate(9);
|
||||
task.update(date);
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run only on week days 2, 3 and 5 ', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * 2,3,5', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
date.setDate(4);
|
||||
task.update(date);
|
||||
date.setDate(5);
|
||||
task.update(date);
|
||||
date.setDate(6);
|
||||
task.update(date);
|
||||
date.setDate(7);
|
||||
task.update(date);
|
||||
date.setDate(8);
|
||||
task.update(date);
|
||||
expect(3).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run in even week days', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * */2', () => {
|
||||
executed += 1;
|
||||
});
|
||||
var date = new Date(2016, 0, 1);
|
||||
date.setDate(4);
|
||||
task.update(date);
|
||||
date.setDate(5);
|
||||
task.update(date);
|
||||
date.setDate(7);
|
||||
task.update(date);
|
||||
expect(2).to.equal(executed);
|
||||
});
|
||||
|
||||
it('should run on monday', () => {
|
||||
let executed = 0;
|
||||
var task = new Task('* * * * Monday', () => {
|
||||
executed += 1;
|
||||
});
|
||||
task.update(new Date(2016, 0, 4));
|
||||
expect(1).to.equal(executed);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
38
node_modules/node-cron/test/timezone-test.js
generated
vendored
Normal file
38
node_modules/node-cron/test/timezone-test.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('scheduling with timezone', () => {
|
||||
beforeEach(() =>{
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() =>{
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should schedule a task without timezone', () => {
|
||||
var executed = 0;
|
||||
cron.schedule('0 0 * * *', () => {
|
||||
executed++;
|
||||
});
|
||||
|
||||
this.clock.tick(1000 * 60 * 60 * 24);
|
||||
expect(executed).to.equal(1);
|
||||
});
|
||||
|
||||
it('should schedule a task with timezone', () => {
|
||||
var executedAt;
|
||||
cron.schedule('0 0 * * *', () => {
|
||||
executedAt = new Date();
|
||||
}, {
|
||||
timezone: 'Etc/UTC'
|
||||
});
|
||||
|
||||
this.clock.tick(1000 * 60 * 60 * 24 + 1);
|
||||
expect(executedAt.getHours()).to.equal(21);
|
||||
});
|
||||
});
|
||||
|
||||
39
node_modules/node-cron/test/validate-taks-schaduling-test.js
generated
vendored
Normal file
39
node_modules/node-cron/test/validate-taks-schaduling-test.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var cron = require('../src/node-cron');
|
||||
|
||||
describe('validate cron on task schaduling', () => {
|
||||
beforeEach(() => {
|
||||
this.clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
this.clock.restore();
|
||||
});
|
||||
|
||||
it('should fail with a invalid cron expression', () => {
|
||||
expect(() => {
|
||||
cron.schedule('65 * * * *', () => {});
|
||||
}).to.throwException(function(e){
|
||||
expect(e).to.equal('65 is a invalid expression for minute');
|
||||
});
|
||||
});
|
||||
|
||||
it('validate some spaces in task string', () => {
|
||||
var result = cron.validate('5 * * * *');
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
|
||||
it('multiple spaces in task string', () => {
|
||||
var result = cron.validate('5 * * * *');
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
|
||||
it('spaces in begin and end of string', () => {
|
||||
var result = cron.validate(' 5 * * * * ');
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user