node-schedule
Advanced tools
Comparing version 1.3.0 to 1.3.3
@@ -14,3 +14,4 @@ | ||
lt = require('long-timeout'), | ||
sorted = require('sorted-array-functions'); | ||
sorted = require('sorted-array-functions'), | ||
nodeVersionUtils = require('./nodeVersionUtils') | ||
@@ -20,2 +21,3 @@ /* Job object */ | ||
var scheduledJobs = {}; | ||
var promisesSupported = nodeVersionUtils.arePromisesSupported(nodeVersionUtils.getNodeVersion(nodeVersionUtils.nodeVersionString)) | ||
@@ -95,3 +97,3 @@ function isValidDate(date) { | ||
if (reschedule && inv.recurrenceRule.recurs) { | ||
if (reschedule && (inv.recurrenceRule.recurs || inv.recurrenceRule.next)) { | ||
newInv = scheduleNextRecurrence(inv.recurrenceRule, this, inv.fireDate, inv.endDate); | ||
@@ -131,3 +133,3 @@ if (newInv !== null) { | ||
if (reschedule && nextInv.recurrenceRule.recurs) { | ||
if (reschedule && (nextInv.recurrenceRule.recurs || nextInv.recurrenceRule.next)) { | ||
newInv = scheduleNextRecurrence(nextInv.recurrenceRule, this, nextInv.fireDate, nextInv.endDate); | ||
@@ -177,3 +179,3 @@ if (newInv !== null) { | ||
this.setTriggeredJobs(this.triggeredJobs() + 1); | ||
this.job(fireDate); | ||
return this.job(fireDate); | ||
} else { | ||
@@ -196,6 +198,10 @@ this.job.execute(fireDate); | ||
// save passed-in value before 'spec' is replaced | ||
if (typeof spec === 'object' && 'tz' in spec) { | ||
tz = spec.tz; | ||
} | ||
if (typeof spec === 'object' && spec.rule) { | ||
start = spec.start || undefined; | ||
end = spec.end || undefined; | ||
tz = spec.tz; | ||
spec = spec.rule; | ||
@@ -407,2 +413,7 @@ | ||
RecurrenceRule.prototype.nextInvocationDate = function(base) { | ||
var next = this._nextInvocationDate(base); | ||
return next ? next.toDate() : null; | ||
}; | ||
RecurrenceRule.prototype._nextInvocationDate = function(base) { | ||
base = ((base instanceof CronDate) || (base instanceof Date)) ? base : (new Date()); | ||
@@ -474,3 +485,3 @@ if (!this.recurs) { | ||
return next ? next.toDate() : null; | ||
return next; | ||
}; | ||
@@ -504,3 +515,3 @@ | ||
var then = date.getTime(); | ||
return lt.setTimeout(function() { | ||
@@ -552,4 +563,14 @@ if (then > Date.now()) | ||
job.invoke(cinv.fireDate instanceof CronDate ? cinv.fireDate.toDate() : cinv.fireDate); | ||
job.emit('run'); | ||
try { | ||
var result = job.invoke(cinv.fireDate instanceof CronDate ? cinv.fireDate.toDate() : cinv.fireDate); | ||
job.emit('run'); | ||
if (promisesSupported && result instanceof Promise) { | ||
result.catch(function (err) { | ||
job.emit('error', err); | ||
}); | ||
} | ||
} catch (err) { | ||
job.emit('error', err); | ||
} | ||
}); | ||
@@ -587,3 +608,3 @@ } | ||
var date = (rule instanceof RecurrenceRule) ? rule.nextInvocationDate(prevDate) : rule.next(); | ||
var date = (rule instanceof RecurrenceRule) ? rule._nextInvocationDate(prevDate) : rule.next(); | ||
if (date === null) { | ||
@@ -590,0 +611,0 @@ return null; |
{ | ||
"name": "node-schedule", | ||
"version": "1.3.0", | ||
"version": "1.3.3", | ||
"description": "A cron-like and not-cron-like job scheduler for Node.", | ||
@@ -9,3 +9,4 @@ "keywords": [ | ||
"job", | ||
"cron" | ||
"cron", | ||
"in-memory" | ||
], | ||
@@ -16,3 +17,6 @@ "license": "MIT", | ||
"test": "nodeunit", | ||
"lint": "eslint lib test" | ||
"test:coverage": "istanbul cover ./node_modules/.bin/nodeunit test", | ||
"test:coverage-win": "istanbul cover ./node_modules/nodeunit/bin/nodeunit test", | ||
"lint": "eslint lib test", | ||
"lint:fix": "eslint --fix lib test" | ||
}, | ||
@@ -24,2 +28,8 @@ "author": { | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Igor Savin", | ||
"email": "kibertoad@gmail.com" | ||
} | ||
], | ||
"repository": { | ||
@@ -30,13 +40,17 @@ "type": "git", | ||
"dependencies": { | ||
"cron-parser": "^2.4.0", | ||
"cron-parser": "^2.18.0", | ||
"long-timeout": "0.1.1", | ||
"sorted-array-functions": "^1.0.0" | ||
"sorted-array-functions": "^1.3.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.2", | ||
"eslint": "^3.19.0", | ||
"eslint": "^7.18.0", | ||
"istanbul": "^0.4.5", | ||
"nodeunit": "^0.10.2", | ||
"sinon": "^1.14.1" | ||
} | ||
"nodeunit": "~0.10.2", | ||
"sinon": "^2.4.1" | ||
}, | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"lib/*" | ||
] | ||
} |
@@ -5,3 +5,4 @@ # Node Schedule | ||
[![Downloads](https://img.shields.io/npm/dm/node-schedule.svg)](https://www.npmjs.com/package/node-schedule) | ||
[![Build Status](https://travis-ci.org/node-schedule/node-schedule.svg?branch=master)](https://travis-ci.org/node-schedule/node-schedule) | ||
[![Build Status](https://github.com/node-schedule/node-schedule/workflows/ci/badge.svg)](https://github.com/node-schedule/node-schedule/actions) | ||
[![Coverage Status](https://coveralls.io/repos/node-schedule/node-schedule/badge.svg?branch=master)](https://coveralls.io/r/node-schedule/node-schedule?branch=master) | ||
[![Join the chat at https://gitter.im/node-schedule/node-schedule](https://img.shields.io/badge/gitter-chat-green.svg)](https://gitter.im/node-schedule/node-schedule?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -47,11 +48,16 @@ | ||
`Job` objects are `EventEmitter`'s, and emit a `run` event after each execution. | ||
They also emit a `scheduled` event each time they're scheduled to run, and a | ||
`canceled` event when an invocation is canceled before it's executed (both events | ||
receive a JavaScript date object as a parameter). Note that jobs are scheduled the | ||
first time immediately, so if you create a job using the `scheduleJob()` | ||
convenience method, you'll miss the first `scheduled` event, but you can query the | ||
invocation manually (see below). Also note that `canceled` is the single-L American | ||
spelling. | ||
`Job` objects are `EventEmitter`s, and emit the following events: | ||
* A `run` event after each execution. | ||
* A `scheduled` event each time they're scheduled to run. | ||
* A `canceled` event when an invocation is canceled before it's executed. | ||
Note that `canceled` is the single-L American spelling. | ||
* An `error` event when a job invocation triggered by a schedule throws or returns | ||
a rejected `Promise`. | ||
(Both the `scheduled` and `canceled` events receive a JavaScript date object as | ||
a parameter). | ||
Note that jobs are scheduled the first time immediately, so if you create a job | ||
using the `scheduleJob()` convenience method, you'll miss the first `scheduled` | ||
event, but you can query the invocation manually (see below). | ||
### Cron-style Scheduling | ||
@@ -103,5 +109,5 @@ | ||
Currently, `W` (nearest weekday), `L` (last day of month/week), and `#` (nth weekday | ||
of the month) are not supported. Most other features supported by popular cron | ||
implementations should work just fine. | ||
Currently, `W` (nearest weekday) and `L` (last day of month/week) are not supported. | ||
Most other features supported by popular cron implementations should work just fine, | ||
including `#` (nth weekday of the month). | ||
@@ -169,12 +175,28 @@ [cron-parser] is used to parse crontab instructions. | ||
Timezones are also supported. Here is an example of executing at the start of every day in the UTC timezone. | ||
```js | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.hour = 0; | ||
rule.tz = 'Etc/UTC'; | ||
var j = schedule.scheduleJob(rule, function(){ | ||
console.log('A new day has begun in the UTC timezone!'); | ||
}); | ||
``` | ||
A list of acceptable tz (timezone) values can be found at <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones> | ||
#### RecurrenceRule properties | ||
- `second` | ||
- `minute` | ||
- `hour` | ||
- `date` | ||
- `month` | ||
- `second (0-59)` | ||
- `minute (0-59)` | ||
- `hour (0-23)` | ||
- `date (1-31)` | ||
- `month (0-11)` | ||
- `year` | ||
- `dayOfWeek` | ||
- `dayOfWeek (0-6) Starting with Sunday` | ||
- `tz` | ||
> **Note**: It's worth noting that the default value of a component of a recurrence rule is | ||
@@ -211,7 +233,7 @@ > `null` (except for second, which is 0 for familiarity with cron). *If we did not | ||
There are some function to get informations for a Job and to handle the Job and | ||
There are some function to get information for a Job and to handle the Job and | ||
Invocations. | ||
#### job.cancel(reshedule) | ||
#### job.cancel(reschedule) | ||
You can invalidate any job with the `cancel()` method: | ||
@@ -225,3 +247,3 @@ | ||
#### job.cancelNext(reshedule) | ||
#### job.cancelNext(reschedule) | ||
This method invalidates the next planned invocation or the job. | ||
@@ -240,5 +262,6 @@ When you set the parameter ***reschedule*** to true then the Job is newly scheduled | ||
This module was originally developed by [Matt Patenaude], and is now maintained by | ||
[Tejas Manohar] and [other wonderful contributors]. | ||
This module was originally developed by [Matt Patenaude] who eventually passed over maintainer's mantle over to [Tejas Manohar]. | ||
Currently it is being maintained by [Igor Savin] and [our amazing community]. | ||
We'd love to get your contributions. Individuals making significant and valuable | ||
@@ -260,5 +283,6 @@ contributions are given commit-access to the project to contribute as they see fit. | ||
[Tejas Manohar]: http://tejas.io | ||
[Igor Savin]: https://twitter.com/kibertoad | ||
[license]: https://github.com/node-schedule/node-schedule/blob/master/LICENSE | ||
[Tejas Manohar]: https://github.com/tejasmanohar | ||
[other wonderful contributors]: https://github.com/node-schedule/node-schedule/graphs/contributors | ||
[our amazing community]: https://github.com/node-schedule/node-schedule/graphs/contributors | ||
[cron-parser]: https://github.com/harrisiirak/cron-parser |
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
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
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4
281
0
30321
5
592
Updatedcron-parser@^2.18.0