Comparing version 2.3.0 to 2.3.1
@@ -10,4 +10,4 @@ (function (root, factory) { | ||
})(this, function (luxon, childProcess) { | ||
var exports = {}; | ||
var spawn = childProcess && childProcess.spawn; | ||
const exports = {}; | ||
const spawn = childProcess && childProcess.spawn; | ||
const CronTime = require('./time')(luxon); | ||
@@ -14,0 +14,0 @@ const CronJob = require('./job')(CronTime, spawn); |
function CronJob(CronTime, spawn) { | ||
function fnWrap(cmd) { | ||
var command; | ||
var args; | ||
let command; | ||
let args; | ||
@@ -17,3 +17,3 @@ switch (typeof cmd) { | ||
args = cmd.args; | ||
var options = cmd.options; | ||
const options = cmd.options; | ||
@@ -39,5 +39,5 @@ return spawn.bind(undefined, command, args, options); | ||
) { | ||
var _cronTime = cronTime; | ||
var argCount = 0; | ||
for (var i = 0; i < arguments.length; i++) { | ||
let _cronTime = cronTime; | ||
let argCount = 0; | ||
for (let i = 0; i < arguments.length; i++) { | ||
if (arguments[i] !== undefined) { | ||
@@ -81,3 +81,3 @@ argCount++; | ||
var addCallback = function (callback) { | ||
const addCallback = function (callback) { | ||
if (typeof callback === 'function') { | ||
@@ -94,5 +94,6 @@ this._callbacks.push(callback); | ||
} | ||
const wasRunning = this.running; | ||
this.stop(); | ||
this.cronTime = time; | ||
this.start(); | ||
if (wasRunning) this.start(); | ||
}; | ||
@@ -104,4 +105,4 @@ | ||
var fireOnTick = function () { | ||
for (var i = this._callbacks.length - 1; i >= 0; i--) { | ||
const fireOnTick = function () { | ||
for (let i = this._callbacks.length - 1; i >= 0; i--) { | ||
this._callbacks[i].call(this.context, this.onComplete); | ||
@@ -116,3 +117,3 @@ } | ||
var start = function () { | ||
const start = function () { | ||
if (this.running) { | ||
@@ -122,7 +123,7 @@ return; | ||
var MAXDELAY = 2147483647; // The maximum number of milliseconds setTimeout will wait. | ||
var self = this; | ||
var timeout = this.cronTime.getTimeout(); | ||
var remaining = 0; | ||
var startTime; | ||
const MAXDELAY = 2147483647; // The maximum number of milliseconds setTimeout will wait. | ||
const self = this; | ||
let timeout = this.cronTime.getTimeout(); | ||
let remaining = 0; | ||
let startTime; | ||
@@ -144,6 +145,6 @@ if (this.cronTime.realDate) { | ||
function callbackWrapper() { | ||
var diff = startTime + timeout - Date.now(); | ||
const diff = startTime + timeout - Date.now(); | ||
if (diff > 0) { | ||
var newTimeout = self.cronTime.getTimeout(); | ||
let newTimeout = self.cronTime.getTimeout(); | ||
@@ -150,0 +151,0 @@ if (newTimeout > diff) { |
@@ -73,3 +73,3 @@ const CONSTRAINTS = [ | ||
if (zone) { | ||
const dt = luxon.DateTime.fromObject({}, { zone: zone }); | ||
const dt = luxon.DateTime.fromObject({}, { zone }); | ||
if (dt.invalid) { | ||
@@ -86,4 +86,4 @@ throw new Error('Invalid timezone.'); | ||
var that = this; | ||
TIME_UNITS.map(timeUnit => { | ||
const that = this; | ||
TIME_UNITS.forEach(timeUnit => { | ||
that[timeUnit] = {}; | ||
@@ -108,15 +108,15 @@ }); | ||
_verifyParse: function () { | ||
var months = Object.keys(this.month); | ||
var dom = Object.keys(this.dayOfMonth); | ||
var ok = false; | ||
const months = Object.keys(this.month); | ||
const dom = Object.keys(this.dayOfMonth); | ||
let ok = false; | ||
/* if a dayOfMonth is not found in all months, we only need to fix the last | ||
wrong month to prevent infinite loop */ | ||
var lastWrongMonth = NaN; | ||
for (var i = 0; i < months.length; i++) { | ||
var m = months[i]; | ||
var con = MONTH_CONSTRAINTS[parseInt(m, 10)]; | ||
let lastWrongMonth = NaN; | ||
for (let i = 0; i < months.length; i++) { | ||
const m = months[i]; | ||
const con = MONTH_CONSTRAINTS[parseInt(m, 10)]; | ||
for (var j = 0; j < dom.length; j++) { | ||
var day = dom[j]; | ||
for (let j = 0; j < dom.length; j++) { | ||
const day = dom[j]; | ||
if (day <= con) { | ||
@@ -136,8 +136,8 @@ ok = true; | ||
if (!ok) { | ||
var notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)]; | ||
for (var k = 0; k < dom.length; k++) { | ||
var notOkDay = dom[k]; | ||
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)]; | ||
for (let k = 0; k < dom.length; k++) { | ||
const notOkDay = dom[k]; | ||
if (notOkDay > notOkCon) { | ||
delete this.dayOfMonth[notOkDay]; | ||
var fixedDay = Number(notOkDay) % notOkCon; | ||
const fixedDay = Number(notOkDay) % notOkCon; | ||
this.dayOfMonth[fixedDay] = true; | ||
@@ -153,3 +153,3 @@ } | ||
sendAt: function (i) { | ||
var date = this.realDate ? this.source : luxon.DateTime.local(); | ||
let date = this.realDate ? this.source : luxon.DateTime.local(); | ||
if (this.zone) { | ||
@@ -193,3 +193,3 @@ date = date.setZone(this.zone); | ||
// return the next schedule times | ||
var dates = []; | ||
const dates = []; | ||
for (; i > 0; i--) { | ||
@@ -222,3 +222,3 @@ date = this._getNextDateFrom(date); | ||
toJSON: function () { | ||
var self = this; | ||
const self = this; | ||
return TIME_UNITS.map(function (timeName) { | ||
@@ -254,4 +254,4 @@ return self._wcOrAll(timeName); | ||
} | ||
var date = start; | ||
var firstDate = start.toMillis(); | ||
let date = start; | ||
const firstDate = start.toMillis(); | ||
if (zone) { | ||
@@ -273,6 +273,6 @@ date = date.setZone(zone); | ||
// infinite loop. | ||
var timeout = Date.now() + 5000; | ||
const timeout = Date.now() + 5000; | ||
// determine next date | ||
while (true) { | ||
var diff = date - start; | ||
const diff = date - start; | ||
@@ -673,4 +673,4 @@ // hard stop if the current date is after the expected execution | ||
var all = []; | ||
for (var time in this[type]) { | ||
const all = []; | ||
for (const time in this[type]) { | ||
all.push(time); | ||
@@ -683,5 +683,5 @@ } | ||
_hasAll: function (type) { | ||
var constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)]; | ||
const constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)]; | ||
for (var i = constraints[0], n = constraints[1]; i < n; i++) { | ||
for (let i = constraints[0], n = constraints[1]; i < n; i++) { | ||
if (!(i in this[type])) { | ||
@@ -721,3 +721,3 @@ return false; | ||
var units = source.trim().split(/\s+/); | ||
const units = source.trim().split(/\s+/); | ||
@@ -733,8 +733,8 @@ // seconds are optional | ||
var unitsLen = units.length; | ||
for (var i = 0; i < TIME_UNITS_LEN; i++) { | ||
const unitsLen = units.length; | ||
for (let i = 0; i < TIME_UNITS_LEN; i++) { | ||
// If the split source string doesn't contain all digits, | ||
// assume defaults for first n missing digits. | ||
// This adds support for 5-digit standard cron syntax | ||
var cur = units[i - (TIME_UNITS_LEN - unitsLen)] || PARSE_DEFAULTS[i]; | ||
const cur = units[i - (TIME_UNITS_LEN - unitsLen)] || PARSE_DEFAULTS[i]; | ||
this._parseField(cur, TIME_UNITS[i], CONSTRAINTS[i]); | ||
@@ -755,10 +755,10 @@ } | ||
_parseField: function (value, type, constraints) { | ||
var typeObj = this[type]; | ||
var pointer; | ||
var low = constraints[0]; | ||
var high = constraints[1]; | ||
const typeObj = this[type]; | ||
let pointer; | ||
const low = constraints[0]; | ||
const high = constraints[1]; | ||
var fields = value.split(','); | ||
const fields = value.split(','); | ||
fields.forEach(field => { | ||
var wildcardIndex = field.indexOf('*'); | ||
const wildcardIndex = field.indexOf('*'); | ||
if (wildcardIndex !== -1 && wildcardIndex !== 0) { | ||
@@ -775,5 +775,5 @@ throw new Error( | ||
// commas separate information, so split based on those | ||
var allRanges = value.split(','); | ||
const allRanges = value.split(','); | ||
for (var i = 0; i < allRanges.length; i++) { | ||
for (let i = 0; i < allRanges.length; i++) { | ||
if (allRanges[i].match(RE_RANGE)) { | ||
@@ -780,0 +780,0 @@ allRanges[i].replace(RE_RANGE, ($0, lower, upper, step) => { |
{ | ||
"name": "cron", | ||
"description": "Cron jobs for your node", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)", | ||
@@ -16,3 +16,4 @@ "bugs": { | ||
"lint": "eslint {lib,tests}/*.js", | ||
"test": "jest --coverage" | ||
"test": "jest --coverage", | ||
"test:watch": "jest --watch --coverage" | ||
}, | ||
@@ -24,15 +25,13 @@ "dependencies": { | ||
"chai": "~4.2.x", | ||
"eslint": "~6.8.x", | ||
"eslint-config-prettier": "^6.11.x", | ||
"eslint-config-standard": "~14.1.x", | ||
"eslint-module-utils": "~2.6.x", | ||
"eslint-plugin-import": "~2.20.x", | ||
"eslint-plugin-jest": "~23.8.x", | ||
"eslint-plugin-node": "~11.1.x", | ||
"eslint-plugin-prettier": "~3.1.x", | ||
"eslint-plugin-promise": "~4.2.x", | ||
"eslint-plugin-standard": "~4.0.x", | ||
"jest": "~28.0.x", | ||
"prettier": "~2.0.x", | ||
"sinon": "^9.0.x" | ||
"eslint": "~8.36.x", | ||
"eslint-config-prettier": "^8.7.x", | ||
"eslint-config-standard": "~17.0.x", | ||
"eslint-plugin-import": "~2.27.x", | ||
"eslint-plugin-jest": "~27.2.x", | ||
"eslint-plugin-n": "~15.6.x", | ||
"eslint-plugin-prettier": "~4.2.x", | ||
"eslint-plugin-promise": "~6.1.x", | ||
"jest": "~29.5.x", | ||
"prettier": "~2.8.x", | ||
"sinon": "^15.0.x" | ||
}, | ||
@@ -50,2 +49,3 @@ "keywords": [ | ||
"contributors": [ | ||
"Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)", | ||
"Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)", | ||
@@ -79,3 +79,9 @@ "James Padolsey <> (https://github.com/jamespadolsey)", | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"lib", | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"README.md" | ||
] | ||
} |
@@ -1,5 +0,5 @@ | ||
## Looking for maintainers/contributors | ||
<p align="center"> | ||
<img src="logo.svg" alt="Node Cron Alarm Clock Star Logo" width="100" /> | ||
</p> | ||
This project is looking for help! If you're interested in helping with the project please reach out to me (ncb000gt) on [Twitter](https://twitter.com/ncb000gt) and let me know. I'd love for it to continue on, but it needs a lot of attention. You can also join the [Discord server](https://discord.gg/yyKns29zch) to learn more about what needs to be done. | ||
# node-cron | ||
@@ -17,4 +17,9 @@ | ||
Cron is a tool that allows you to execute _something_ on a schedule. This is typically done using the cron syntax. We allow you to execute a function whenever your scheduled job triggers. We also allow you to execute a job external to the javascript process using `child_process`. Additionally, this library goes beyond the basic cron syntax and allows you to supply a Date object. This will be used as the trigger for your callback. Cron syntax is still an acceptable CronTime format. Although the Cron patterns supported here extend on the standard Unix format to support seconds digits, leaving it off will default to 0 and match the Unix behavior. | ||
Cron is a tool that allows you to execute _something_ on a schedule. This is typically done using the cron syntax. We allow you to: | ||
- execute a function whenever your scheduled job triggers | ||
- execute a job external to the javascript process using `child_process` | ||
- use a Date object instead of cron syntax as the trigger for your callback | ||
- use an additional slot for seconds (leaving it off will default to 0 and match the Unix behavior) | ||
## Installation | ||
@@ -26,7 +31,7 @@ | ||
## Versions and Backwards compatibility breaks: | ||
## Versions and Backwards compatibility breaks | ||
As goes with semver, breaking backwards compatibility should be explicit in the versioning of your library. As such, we'll upgrade the version of this module in accordance with breaking changes (I'm not always great about doing it this way so if you notice that there are breaking changes that haven't been bumped appropriately please let me know). | ||
As goes with semver, breaking backwards compatibility should be explicit in the versioning of your library. As such, we'll upgrade the version of this module in accordance with breaking changes (We're not always great about doing it this way so if you notice that there are breaking changes that haven't been bumped appropriately please let us know). | ||
## Usage (basic cron usage): | ||
## Usage (basic cron usage) | ||
@@ -44,11 +49,10 @@ ```javascript | ||
); | ||
// Use this if the 4th param is default value(false) | ||
// job.start() | ||
// job.start() - See note below when to use this | ||
``` | ||
Note - You don't need to explicitly start a job in order to make it run since the 4th parameter is set to `true`. However, by default you need to call `job.start()` to start the cron job, which gives a little more control over running your jobs. | ||
Note - In the example above, the 4th parameter of `CronJob()` automatically starts the job on initialization. If this parameter is falsy or not provided, the job needs to be explicitly started using `job.start()`. | ||
There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/master/examples) | ||
## Available Cron patterns: | ||
## Available Cron patterns | ||
@@ -78,3 +82,3 @@ ``` | ||
- Millisecond level granularity in JS `Date` or Luxon `DateTime` objects: Because computers take time to do things, there may be some delay in execution. This should be on the order of milliseconds. This module doesn't allow MS level granularity for the regular cron syntax, but _does_ allow you to specify a real date of execution in either a javascript `Date` object or a Luxon `DateTime` object. When this happens you may find that you aren't able to execute a job that _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution above. This wont be the same for everyone because of compute speed. When I tried it locally I saw that somewhere around the 4-5 ms mark was where I got consistent ticks using real dates, but anything less than that would result in an exception. This could be really confusing. We could restrict the granularity for all dates to seconds, but felt that it wasn't a huge problem so long as you were made aware. If this becomes more of an issue, We can revisit it. | ||
- Millisecond level granularity in JS `Date` or Luxon `DateTime` objects: Because computers take time to do things, there may be some delay in execution. This should be on the order of milliseconds. This module doesn't allow MS level granularity for the regular cron syntax, but _does_ allow you to specify a real date of execution in either a javascript `Date` object or a Luxon `DateTime` object. When this happens you may find that you aren't able to execute a job that _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution above. This wont be the same for everyone because of compute speed. When we tried it locally we saw that somewhere around the 4-5 ms mark was where we got consistent ticks using real dates, but anything less than that would result in an exception. This could be really confusing. We could restrict the granularity for all dates to seconds, but felt that it wasn't a huge problem so long as you were made aware. If this becomes more of an issue, We can revisit it. | ||
- Arrow Functions for `onTick`: Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get the `this` context of the cronjob. You can read a little more in issue [GH-47](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775) | ||
@@ -118,2 +122,6 @@ | ||
### Looking for maintainers/contributors | ||
This project is looking for help! If you're interested in helping with the project please reach out to me (ncb000gt) on [Twitter](https://twitter.com/ncb000gt). We'd love for it to continue on, but it needs a lot of attention. You can also join the [Discord server](https://discord.gg/yyKns29zch) to learn more about what needs to be done. | ||
### Submitting Bugs/Issues | ||
@@ -127,6 +135,6 @@ | ||
This is a community effort project. In the truest sense, this project started as an open source project from [cron.js](http://github.com/padolsey/cron.js) and grew into something else. Other people have contributed code, time, and oversight to the project. At this point there are too many to name here so I'll just say thanks. | ||
This is a community effort project. In the truest sense, this project started as an open source project from [cron.js](http://github.com/padolsey/cron.js) and grew into something else. Other people have contributed code, time, and oversight to the project. At this point there are too many to name here so We'll just say thanks. | ||
## License | ||
MIT | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12
135
46164
7
937