cron 2.3.1 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -7
- package/LICENSE +0 -0
- package/README.md +34 -11
- package/lib/cron.js +0 -0
- package/lib/job.js +0 -0
- package/lib/time.js +41 -28
- package/package.json +17 -2
- package/types/index.d.ts +181 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,78 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### ⚠ Breaking changes
|
|
5
|
+
|
|
6
|
+
* UNIX standard alignments (#667)
|
|
7
|
+
|
|
8
|
+
### ✨ Features
|
|
9
|
+
|
|
10
|
+
* UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### ⚙️ Continuous Integrations
|
|
14
|
+
|
|
15
|
+
* add support for beta & maintenance releases ([#677](https://github.com/kelektiv/node-cron/issues/677)) ([c6fc842](https://github.com/kelektiv/node-cron/commit/c6fc8429e905b38b05ba428e0df4a0fea273614a))
|
|
16
|
+
* setup conventional commits & release automation ([#673](https://github.com/kelektiv/node-cron/issues/673)) ([c6f39ff](https://github.com/kelektiv/node-cron/commit/c6f39ff384041b7f91566fc935a9b961d453dd14))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### ♻️ Chores
|
|
20
|
+
|
|
21
|
+
* update default branch name ([#678](https://github.com/kelektiv/node-cron/issues/678)) ([7471e95](https://github.com/kelektiv/node-cron/commit/7471e95cb7433b4f29cfa68da0a652ec8cf630b6))
|
|
22
|
+
|
|
23
|
+
## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Logo!
|
|
28
|
+
- New test cases
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Linting issues
|
|
33
|
+
|
|
34
|
+
## [v2.3.0](https://github.com/kelektiv/node-cron/compare/v2.2.0...v2.3.0) (2023-03-14)
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- Some small bugs
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- Refactored get next date function
|
|
43
|
+
|
|
44
|
+
## [v2.2.0](https://github.com/kelektiv/node-cron/compare/v2.1.0...v2.2.0) (2023-01-09)
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
- Updated Luxon dependency
|
|
49
|
+
- Updated unit tests to be compatible with new Luxon version
|
|
50
|
+
|
|
51
|
+
## [v2.1.0](https://github.com/kelektiv/node-cron/compare/v2.0.0...v2.1.0) (2022-07-14)
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- "Maximum iterations" will direct the user to refer to a single canonical issue instead of creating a new one
|
|
56
|
+
|
|
57
|
+
## [v2.0.0](https://github.com/kelektiv/node-cron/compare/v1.8.2...v2.0.0) (2022-05-03)
|
|
2
58
|
- Upgrade vulnerable dependencies
|
|
3
59
|
- Move from moment.js to luxon (breaking change)
|
|
4
60
|
|
|
5
|
-
## [v1.8.2]
|
|
61
|
+
## [v1.8.2](https://github.com/kelektiv/node-cron/compare/v1.8.1...v1.8.2) (2020-01-24)
|
|
6
62
|
- Fix syntax parsing bug
|
|
7
63
|
|
|
8
|
-
## [v1.8.1]
|
|
64
|
+
## [v1.8.1](https://github.com/kelektiv/node-cron/compare/v1.8.0...v1.8.1) (2020-01-19)
|
|
9
65
|
- Revert TS definition defaulting to DefinitelyTyped definitions.
|
|
10
66
|
|
|
11
|
-
## [v1.8.0]
|
|
67
|
+
## [v1.8.0](https://github.com/kelektiv/node-cron/compare/v1.7.1...v1.8.0) (2020-01-19)
|
|
12
68
|
- GH-454 - Range upper limit should default to highest value when step is provided by Noah May <noahmouse2011@gmail.com> in d36dc9581f9f68580a2016b368f8002a9f1e357d
|
|
13
69
|
|
|
14
|
-
## [v1.7.1]
|
|
70
|
+
## [v1.7.1](https://github.com/kelektiv/node-cron/compare/v1.7.0...v1.7.1) (2019-04-26)
|
|
15
71
|
- GH-416 - Fix issue where next execution time is incorrect in some cases in Naoya Inada <naoina@kuune.org> in c08522ff80b3987843e9930c307b76d5fe38b5dc
|
|
16
72
|
|
|
17
|
-
## [v1.7.0]
|
|
73
|
+
## [v1.7.0](https://github.com/kelektiv/node-cron/compare/v1.6.0...v1.7.0) (2019-03-19)
|
|
18
74
|
- GH-408 - DST issue by Shua Talansky <shua@bitbean.com> in 1e971fd6dfa6ba4b0469d99dd64e6c31189d17d3 and 849a2467d16216a9dfa818c57cc26be6b6d0899b
|
|
19
75
|
|
|
20
|
-
## [v1.6.0]
|
|
76
|
+
## [v1.6.0](https://github.com/kelektiv/node-cron/compare/v1.5.1...v1.6.0) (2018-11-15)
|
|
21
77
|
- GH-393, GH-394 - Remove hard limit on max iters in favor of a timeout by Nick Campbell <nicholas.j.campbell@gmail.com> in 57632b0c06c56e82f40b740b8d7986be43842735
|
|
22
78
|
- GH-390 - better handling of real dates which are in the past by Nick Campbell <nicholas.j.campbell@gmail.com> in 7cbcc984aea6ec063e38829f68eb9bc0dfb1c775
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -27,6 +27,21 @@ Cron is a tool that allows you to execute _something_ on a schedule. This is typ
|
|
|
27
27
|
npm install cron
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Migrating from v2 to v3
|
|
31
|
+
|
|
32
|
+
In version 3 of this library, we aligned our format for the cron patterns with the UNIX format. See below for the changes you need to make when upgrading:
|
|
33
|
+
|
|
34
|
+
<details>
|
|
35
|
+
<summary>Migrating from v2 to v3</summary>
|
|
36
|
+
|
|
37
|
+
### Month & day-of-week indexing changes
|
|
38
|
+
|
|
39
|
+
**Month indexing went from `0-11` to `1-12`. So you need to increment all numeric months by 1.**
|
|
40
|
+
|
|
41
|
+
For day-of-week indexing, we only added support for `7` as Sunday, so you don't need to change anything !
|
|
42
|
+
|
|
43
|
+
</details>
|
|
44
|
+
|
|
30
45
|
## Versions and Backwards compatibility breaks
|
|
31
46
|
|
|
32
47
|
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).
|
|
@@ -49,7 +64,7 @@ var job = new CronJob(
|
|
|
49
64
|
|
|
50
65
|
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()`.
|
|
51
66
|
|
|
52
|
-
There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/
|
|
67
|
+
There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/main/examples)
|
|
53
68
|
|
|
54
69
|
## Available Cron patterns
|
|
55
70
|
|
|
@@ -65,17 +80,25 @@ There are tools that help when constructing your cronjobs. You might find someth
|
|
|
65
80
|
|
|
66
81
|
### Cron Ranges
|
|
67
82
|
|
|
68
|
-
|
|
83
|
+
This library follows the [UNIX Cron format](https://man7.org/linux/man-pages/man5/crontab.5.html), with an added field at the beginning for second granularity.
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
field allowed values
|
|
87
|
+
----- --------------
|
|
88
|
+
second 0-59
|
|
89
|
+
minute 0-59
|
|
90
|
+
hour 0-23
|
|
91
|
+
day of month 1-31
|
|
92
|
+
month 1-12 (or names, see below)
|
|
93
|
+
day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
94
|
+
```
|
|
69
95
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- Hours: 0-23
|
|
73
|
-
- Day of Month: 1-31
|
|
74
|
-
- Months: 0-11 (Jan-Dec)
|
|
75
|
-
- Day of Week: 0-6 (Sun-Sat)
|
|
96
|
+
> Names can also be used for the 'month' and 'day of week' fields. Use the first three letters of the particular day or month (case does not matter). Ranges and lists of names are allowed.
|
|
97
|
+
> Examples: "mon,wed,fri", "jan-mar".
|
|
76
98
|
|
|
77
99
|
## Gotchas
|
|
78
100
|
|
|
101
|
+
- Months are indexed as 0-11 instead of 1-12. This is different from Unix `cron` and is planned to updated to match Unix `cron` in v3.0.0 of `node-cron`.
|
|
79
102
|
- 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.
|
|
80
103
|
- 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)
|
|
81
104
|
|
|
@@ -88,15 +111,15 @@ Parameter Based
|
|
|
88
111
|
- `sendAt` - tells you when a `CronTime` will be run.
|
|
89
112
|
- `timeout` - tells you when the next timeout is.
|
|
90
113
|
- `CronJob`
|
|
91
|
-
- `constructor(cronTime, onTick, onComplete, start,
|
|
114
|
+
- `constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
|
|
92
115
|
- `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
|
|
93
116
|
- `onTick` - [REQUIRED] - The function to fire at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument. `onTick` may call `onComplete` when it has finished its work.
|
|
94
117
|
- `onComplete` - [OPTIONAL] - A function that will fire when the job is stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
|
|
95
118
|
- `start` - [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call `job.start()` in order to start the job (assuming `job` is the variable you set the cronjob to). This does not immediately fire your `onTick` function, it just gives you more control over the behavior of your jobs.
|
|
96
|
-
- `timeZone` - [OPTIONAL] - Specify the
|
|
119
|
+
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check all time zones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
|
|
97
120
|
- `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
|
|
98
121
|
- `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick` function as soon as the requisite initialization has happened. This option is set to `false` by default for backwards compatibility.
|
|
99
|
-
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your
|
|
122
|
+
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
|
|
100
123
|
- `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.
|
|
101
124
|
- `start` - Runs your job.
|
|
102
125
|
- `stop` - Stops your job.
|
package/lib/cron.js
CHANGED
|
File without changes
|
package/lib/job.js
CHANGED
|
File without changes
|
package/lib/time.js
CHANGED
|
@@ -3,8 +3,8 @@ const CONSTRAINTS = [
|
|
|
3
3
|
[0, 59],
|
|
4
4
|
[0, 23],
|
|
5
5
|
[1, 31],
|
|
6
|
-
[
|
|
7
|
-
[0,
|
|
6
|
+
[1, 12],
|
|
7
|
+
[0, 7]
|
|
8
8
|
];
|
|
9
9
|
const MONTH_CONSTRAINTS = [
|
|
10
10
|
31,
|
|
@@ -22,18 +22,18 @@ const MONTH_CONSTRAINTS = [
|
|
|
22
22
|
];
|
|
23
23
|
const PARSE_DEFAULTS = ['0', '*', '*', '*', '*', '*'];
|
|
24
24
|
const ALIASES = {
|
|
25
|
-
jan:
|
|
26
|
-
feb:
|
|
27
|
-
mar:
|
|
28
|
-
apr:
|
|
29
|
-
may:
|
|
30
|
-
jun:
|
|
31
|
-
jul:
|
|
32
|
-
aug:
|
|
33
|
-
sep:
|
|
34
|
-
oct:
|
|
35
|
-
nov:
|
|
36
|
-
dec:
|
|
25
|
+
jan: 1,
|
|
26
|
+
feb: 2,
|
|
27
|
+
mar: 3,
|
|
28
|
+
apr: 4,
|
|
29
|
+
may: 5,
|
|
30
|
+
jun: 6,
|
|
31
|
+
jul: 7,
|
|
32
|
+
aug: 8,
|
|
33
|
+
sep: 9,
|
|
34
|
+
oct: 10,
|
|
35
|
+
nov: 11,
|
|
36
|
+
dec: 12,
|
|
37
37
|
sun: 0,
|
|
38
38
|
mon: 1,
|
|
39
39
|
tue: 2,
|
|
@@ -42,17 +42,18 @@ const ALIASES = {
|
|
|
42
42
|
fri: 5,
|
|
43
43
|
sat: 6
|
|
44
44
|
};
|
|
45
|
-
const
|
|
46
|
-
'second',
|
|
47
|
-
'minute',
|
|
48
|
-
'hour',
|
|
49
|
-
'dayOfMonth',
|
|
50
|
-
'month',
|
|
51
|
-
'dayOfWeek'
|
|
52
|
-
|
|
45
|
+
const TIME_UNITS_MAP = {
|
|
46
|
+
SECOND: 'second',
|
|
47
|
+
MINUTE: 'minute',
|
|
48
|
+
HOUR: 'hour',
|
|
49
|
+
DAY_OF_MONTH: 'dayOfMonth',
|
|
50
|
+
MONTH: 'month',
|
|
51
|
+
DAY_OF_WEEK: 'dayOfWeek'
|
|
52
|
+
};
|
|
53
|
+
const TIME_UNITS = Object.values(TIME_UNITS_MAP);
|
|
53
54
|
const TIME_UNITS_LEN = TIME_UNITS.length;
|
|
54
55
|
const PRESETS = {
|
|
55
|
-
'@yearly': '0 0 0 1
|
|
56
|
+
'@yearly': '0 0 0 1 1 *',
|
|
56
57
|
'@monthly': '0 0 0 1 * *',
|
|
57
58
|
'@weekly': '0 0 0 * * 0',
|
|
58
59
|
'@daily': '0 0 0 * * *',
|
|
@@ -112,7 +113,7 @@ function CronTime(luxon) {
|
|
|
112
113
|
let lastWrongMonth = NaN;
|
|
113
114
|
for (let i = 0; i < months.length; i++) {
|
|
114
115
|
const m = months[i];
|
|
115
|
-
const con = MONTH_CONSTRAINTS[parseInt(m, 10)];
|
|
116
|
+
const con = MONTH_CONSTRAINTS[parseInt(m, 10) - 1];
|
|
116
117
|
|
|
117
118
|
for (let j = 0; j < dom.length; j++) {
|
|
118
119
|
const day = dom[j];
|
|
@@ -130,7 +131,7 @@ function CronTime(luxon) {
|
|
|
130
131
|
|
|
131
132
|
// infinite loop detected (dayOfMonth is not found in all months)
|
|
132
133
|
if (!ok) {
|
|
133
|
-
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)];
|
|
134
|
+
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10) - 1];
|
|
134
135
|
for (let k = 0; k < dom.length; k++) {
|
|
135
136
|
const notOkDay = dom[k];
|
|
136
137
|
if (notOkDay > notOkCon) {
|
|
@@ -278,7 +279,7 @@ function CronTime(luxon) {
|
|
|
278
279
|
}
|
|
279
280
|
|
|
280
281
|
if (
|
|
281
|
-
!(date.month
|
|
282
|
+
!(date.month in this.month) &&
|
|
282
283
|
Object.keys(this.month).length !== 12
|
|
283
284
|
) {
|
|
284
285
|
date = date.plus({ months: 1 });
|
|
@@ -471,7 +472,7 @@ function CronTime(luxon) {
|
|
|
471
472
|
const beforeJumpingPoint = afterJumpingPoint.minus({ second: 1 });
|
|
472
473
|
|
|
473
474
|
if (
|
|
474
|
-
date.month in this.month &&
|
|
475
|
+
date.month + 1 in this.month &&
|
|
475
476
|
date.day in this.dayOfMonth &&
|
|
476
477
|
date.getWeekDay() in this.dayOfWeek
|
|
477
478
|
) {
|
|
@@ -671,8 +672,13 @@ function CronTime(luxon) {
|
|
|
671
672
|
|
|
672
673
|
_hasAll: function (type) {
|
|
673
674
|
const constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)];
|
|
675
|
+
const low = constraints[0];
|
|
676
|
+
const high =
|
|
677
|
+
type === TIME_UNITS_MAP.DAY_OF_WEEK
|
|
678
|
+
? constraints[1] - 1
|
|
679
|
+
: constraints[1];
|
|
674
680
|
|
|
675
|
-
for (let i =
|
|
681
|
+
for (let i = low, n = high; i < n; i++) {
|
|
676
682
|
if (!(i in this[type])) {
|
|
677
683
|
return false;
|
|
678
684
|
}
|
|
@@ -803,6 +809,13 @@ function CronTime(luxon) {
|
|
|
803
809
|
typeObj[pointer] = true; // mutates the field objects values inside CronTime
|
|
804
810
|
pointer += step;
|
|
805
811
|
} while (pointer <= upper);
|
|
812
|
+
|
|
813
|
+
// merge day 7 into day 0 (both Sunday), and remove day 7
|
|
814
|
+
// since we work with day-of-week 0-6 under the hood
|
|
815
|
+
if (type === 'dayOfWeek') {
|
|
816
|
+
if (!typeObj[0] && !!typeObj[7]) typeObj[0] = typeObj[7];
|
|
817
|
+
delete typeObj[7];
|
|
818
|
+
}
|
|
806
819
|
});
|
|
807
820
|
} else {
|
|
808
821
|
throw new Error(`Field (${type}) cannot be parsed`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0-beta.1",
|
|
5
5
|
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/kelektiv/node-cron/issues"
|
|
@@ -14,12 +14,24 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"lint": "eslint {lib,tests}/*.js",
|
|
16
16
|
"test": "jest --coverage",
|
|
17
|
-
"test:watch": "jest --watch --coverage"
|
|
17
|
+
"test:watch": "jest --watch --coverage",
|
|
18
|
+
"prepare": "husky install",
|
|
19
|
+
"release": "semantic-release"
|
|
18
20
|
},
|
|
21
|
+
"types": "types/index.d.ts",
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"luxon": "^3.2.1"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
26
|
+
"@commitlint/cli": "~17.6.6",
|
|
27
|
+
"@insurgentlab/commitlint-config": "^18.1.0",
|
|
28
|
+
"@insurgentlab/conventional-changelog-preset": "~6.0.3",
|
|
29
|
+
"@semantic-release/changelog": "~6.0.x",
|
|
30
|
+
"@semantic-release/commit-analyzer": "~9.0.x",
|
|
31
|
+
"@semantic-release/git": "~10.0.x",
|
|
32
|
+
"@semantic-release/github": "~8.1.x",
|
|
33
|
+
"@semantic-release/npm": "~10.0.x",
|
|
34
|
+
"@semantic-release/release-notes-generator": "~11.0.x",
|
|
23
35
|
"chai": "~4.2.x",
|
|
24
36
|
"eslint": "~8.36.x",
|
|
25
37
|
"eslint-config-prettier": "^8.7.x",
|
|
@@ -29,8 +41,10 @@
|
|
|
29
41
|
"eslint-plugin-n": "~15.6.x",
|
|
30
42
|
"eslint-plugin-prettier": "~4.2.x",
|
|
31
43
|
"eslint-plugin-promise": "~6.1.x",
|
|
44
|
+
"husky": "^8.0.3",
|
|
32
45
|
"jest": "~29.5.x",
|
|
33
46
|
"prettier": "~2.8.x",
|
|
47
|
+
"semantic-release": "~21.0.x",
|
|
34
48
|
"sinon": "^15.0.x"
|
|
35
49
|
},
|
|
36
50
|
"keywords": [
|
|
@@ -76,6 +90,7 @@
|
|
|
76
90
|
},
|
|
77
91
|
"files": [
|
|
78
92
|
"lib",
|
|
93
|
+
"types",
|
|
79
94
|
"CHANGELOG.md",
|
|
80
95
|
"LICENSE",
|
|
81
96
|
"README.md"
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Type definitions for cron 2.0
|
|
2
|
+
// Project: https://www.npmjs.com/package/cron
|
|
3
|
+
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>
|
|
4
|
+
// Lundarl Gholoi <https://github.com/winup>
|
|
5
|
+
// koooge <https://github.com/koooge>
|
|
6
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
7
|
+
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
|
|
10
|
+
import { SpawnOptions } from 'child_process';
|
|
11
|
+
import { DateTime } from 'luxon';
|
|
12
|
+
|
|
13
|
+
export declare type CronCommand =
|
|
14
|
+
| (() => void)
|
|
15
|
+
| string
|
|
16
|
+
| {
|
|
17
|
+
command: string;
|
|
18
|
+
args?: ReadonlyArray<string> | undefined;
|
|
19
|
+
options?: SpawnOptions | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export declare class CronTime {
|
|
23
|
+
/**
|
|
24
|
+
* Create a new ```CronTime```.
|
|
25
|
+
* @param source The time to fire off your job. This can be in the form of cron syntax, a JS ```Date``` object, or a luxon ```DateTime``` object.
|
|
26
|
+
* @param zone Timezone name. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone).
|
|
27
|
+
* @param utcOffset UTC offset. Don't use both ```zone``` and ```utcOffset``` together or weird things may happen.
|
|
28
|
+
*/
|
|
29
|
+
constructor(
|
|
30
|
+
source: string | Date | DateTime,
|
|
31
|
+
zone?: string,
|
|
32
|
+
utcOffset?: string | number
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Tells you when ```CronTime``` will be run.
|
|
37
|
+
*/
|
|
38
|
+
public sendAt(): DateTime;
|
|
39
|
+
/**
|
|
40
|
+
* Tells you when ```CronTime``` will be run.
|
|
41
|
+
* @param i Indicate which turn of run after now. If not given return next run time.
|
|
42
|
+
* @returns A ```DateTime``` when the source passed in the constructor is a ```Date``` or a ```DateTime``` and an array of ```DateTime``` when the source is a string.
|
|
43
|
+
*/
|
|
44
|
+
public sendAt(i?: number): DateTime | DateTime[];
|
|
45
|
+
/**
|
|
46
|
+
* Get the number of milliseconds in the future at which to fire our callbacks.
|
|
47
|
+
*/
|
|
48
|
+
public getTimeout(): number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare interface CronJobParameters {
|
|
52
|
+
/**
|
|
53
|
+
* The time to fire off your job. This can be in the form of cron syntax, a JS ```Date``` object, or a luxon ```DateTime``` object.
|
|
54
|
+
*/
|
|
55
|
+
cronTime: string | Date | DateTime;
|
|
56
|
+
/**
|
|
57
|
+
* The function to fire at the specified time. If an ```onComplete``` callback was provided, ```onTick``` will receive it as an argument. ```onTick``` may call ```onComplete``` when it has finished its work.
|
|
58
|
+
*/
|
|
59
|
+
onTick: CronCommand;
|
|
60
|
+
/**
|
|
61
|
+
* A function that will fire when the job is stopped with ```job.stop()```, and may also be called by ```onTick``` at the end of each run.
|
|
62
|
+
*/
|
|
63
|
+
onComplete?: CronCommand | null | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call ```job.start()``` in order to start the job (assuming ```job``` is the variable you set the cronjob to). This does not immediately fire your ```onTick``` function, it just gives you more control over the behavior of your jobs.
|
|
66
|
+
*/
|
|
67
|
+
start?: boolean | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone). Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.
|
|
70
|
+
*/
|
|
71
|
+
timeZone?: string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call ```this.stop()```. However, if you change this you'll have access to the functions and values within your context object.
|
|
74
|
+
*/
|
|
75
|
+
context?: any;
|
|
76
|
+
/**
|
|
77
|
+
* This will immediately fire your ```onTick``` function as soon as the requisit initialization has happened. This option is set to ```false``` by default for backwards compatibility.
|
|
78
|
+
*/
|
|
79
|
+
runOnInit?: boolean | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* This allows you to specify the offset of your timezone rather than using the ```timeZone``` param. Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.
|
|
82
|
+
*/
|
|
83
|
+
utcOffset?: string | number | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.
|
|
86
|
+
*/
|
|
87
|
+
unrefTimeout?: boolean | undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare class CronJob {
|
|
91
|
+
/**
|
|
92
|
+
* Return ```true``` if job is running.
|
|
93
|
+
*/
|
|
94
|
+
public running: boolean | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Function using to fire ```onTick```, default set to an inner private function. Overwrite this only if you have a really good reason to do so.
|
|
97
|
+
*/
|
|
98
|
+
public fireOnTick: Function;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Create a new ```CronJob```.
|
|
102
|
+
* @param cronTime The time to fire off your job. This can be in the form of cron syntax or a JS ```Date``` object.
|
|
103
|
+
* @param onTick The function to fire at the specified time.
|
|
104
|
+
* @param onComplete A function that will fire when the job is complete, when it is stopped.
|
|
105
|
+
* @param startNow Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call ```job.start()``` in order to start the job (assuming ```job``` is the variable you set the cronjob to). This does not immediately fire your onTick function, it just gives you more control over the behavior of your jobs.
|
|
106
|
+
* @param timeZone Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone).
|
|
107
|
+
* @param context The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call ```this.stop()```. However, if you change this you'll have access to the functions and values within your context object.
|
|
108
|
+
* @param runOnInit This will immediately fire your ```onTick``` function as soon as the requisit initialization has happened. This option is set to ```false``` by default for backwards compatibility.
|
|
109
|
+
* @param utcOffset This allows you to specify the offset of your timezone rather than using the ```timeZone``` param. Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.
|
|
110
|
+
* @param unrefTimeout If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.
|
|
111
|
+
*/
|
|
112
|
+
constructor(
|
|
113
|
+
cronTime: string | Date | DateTime,
|
|
114
|
+
onTick: CronCommand,
|
|
115
|
+
onComplete?: CronCommand | null,
|
|
116
|
+
startNow?: boolean,
|
|
117
|
+
timeZone?: string,
|
|
118
|
+
context?: any,
|
|
119
|
+
runOnInit?: boolean,
|
|
120
|
+
utcOffset?: string | number,
|
|
121
|
+
unrefTimeout?: boolean
|
|
122
|
+
);
|
|
123
|
+
/**
|
|
124
|
+
* Create a new ```CronJob```.
|
|
125
|
+
* @param options Job parameters.
|
|
126
|
+
*/
|
|
127
|
+
constructor(options: CronJobParameters);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Runs your job.
|
|
131
|
+
*/
|
|
132
|
+
public start(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Stops your job.
|
|
135
|
+
*/
|
|
136
|
+
public stop(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Change the time for the ```CronJob```.
|
|
139
|
+
* @param time Target time.
|
|
140
|
+
*/
|
|
141
|
+
public setTime(time: CronTime): void;
|
|
142
|
+
/**
|
|
143
|
+
* Tells you the last execution date.
|
|
144
|
+
*/
|
|
145
|
+
public lastDate(): Date;
|
|
146
|
+
/**
|
|
147
|
+
* Tells you when a ```CronTime``` will be run.
|
|
148
|
+
*/
|
|
149
|
+
public nextDate(): DateTime;
|
|
150
|
+
public nextDates(): DateTime;
|
|
151
|
+
/**
|
|
152
|
+
* Tells you when a ```CronTime``` will be run.
|
|
153
|
+
* @param i Indicate which turn of run after now. If not given return next run time.
|
|
154
|
+
* @returns A `DateTime` when the cronTime passed in the constructor is a `Date` or a `DateTime` and an array of `DateTime` when the cronTime is a string.
|
|
155
|
+
*/
|
|
156
|
+
public nextDates(i?: number): DateTime | DateTime[];
|
|
157
|
+
/**
|
|
158
|
+
* Add another ```onTick``` function.
|
|
159
|
+
* @param callback Target function.
|
|
160
|
+
*/
|
|
161
|
+
public addCallback(callback: Function): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export declare function job(options: CronJobParameters): CronJob;
|
|
165
|
+
export declare function job(
|
|
166
|
+
cronTime: string | Date | DateTime,
|
|
167
|
+
onTick: () => void,
|
|
168
|
+
onComplete?: CronCommand | null,
|
|
169
|
+
start?: boolean,
|
|
170
|
+
timeZone?: string,
|
|
171
|
+
context?: any,
|
|
172
|
+
runOnInit?: boolean,
|
|
173
|
+
utcOffset?: string | number,
|
|
174
|
+
unrefTimeout?: boolean
|
|
175
|
+
): CronJob;
|
|
176
|
+
export declare function time(
|
|
177
|
+
source: string | Date | DateTime,
|
|
178
|
+
zone?: string
|
|
179
|
+
): CronTime;
|
|
180
|
+
export declare function sendAt(cronTime: string | Date | DateTime): DateTime;
|
|
181
|
+
export declare function timeout(cronTime: string | Date | DateTime): number;
|