cron 3.1.4 → 3.1.6
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 +49 -0
- package/README.md +163 -79
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +5 -2
- package/dist/job.d.ts +1 -0
- package/dist/job.js +8 -2
- package/dist/time.js +17 -17
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
+
## [3.1.6](https://github.com/kelektiv/node-cron/compare/v3.1.5...v3.1.6) (2023-10-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🐛 Bug Fixes
|
|
5
|
+
|
|
6
|
+
* revert runOnce breaking changes ([#760](https://github.com/kelektiv/node-cron/issues/760)) ([7cb53ec](https://github.com/kelektiv/node-cron/commit/7cb53ec9944b19ed5ba92b2466e73fc158ef1d11))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ⚙️ Continuous Integrations
|
|
10
|
+
|
|
11
|
+
* **action:** update actions/checkout action to v4 ([#755](https://github.com/kelektiv/node-cron/issues/755)) ([d0d70c6](https://github.com/kelektiv/node-cron/commit/d0d70c67532b9a2563ed7a4273901f85b314d1b9))
|
|
12
|
+
* **action:** update github/codeql-action action to v2.22.4 ([#752](https://github.com/kelektiv/node-cron/issues/752)) ([04454c3](https://github.com/kelektiv/node-cron/commit/04454c34a5cbfcffb6938173393380840a7c8d75))
|
|
13
|
+
* **action:** update github/codeql-action action to v2.22.5 ([#758](https://github.com/kelektiv/node-cron/issues/758)) ([2dff183](https://github.com/kelektiv/node-cron/commit/2dff1838a6b8ee400ad721c7a41065ee73a42b8a))
|
|
14
|
+
* **action:** update ossf/scorecard-action action to v2.3.1 ([#754](https://github.com/kelektiv/node-cron/issues/754)) ([41d21f1](https://github.com/kelektiv/node-cron/commit/41d21f16b58dc76e48c81751c8782b6c6c1ac7ca))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### ♻️ Chores
|
|
18
|
+
|
|
19
|
+
* **deps:** update dependency [@commitlint](https://github.com/commitlint)/cli to v18.2.0 ([#759](https://github.com/kelektiv/node-cron/issues/759)) ([4cb466e](https://github.com/kelektiv/node-cron/commit/4cb466e183016861098cb4252b48cb54fb0ea96d))
|
|
20
|
+
* **deps:** update dependency [@types](https://github.com/types)/node to v20.8.8 ([#756](https://github.com/kelektiv/node-cron/issues/756)) ([361728e](https://github.com/kelektiv/node-cron/commit/361728ebf8bc6a3202001fccaf6661e9417054a1))
|
|
21
|
+
* **deps:** update dependency [@types](https://github.com/types)/node to v20.8.9 ([#757](https://github.com/kelektiv/node-cron/issues/757)) ([e2b1bac](https://github.com/kelektiv/node-cron/commit/e2b1bac21b59b9bd02a9000ec1c885961d07e121))
|
|
22
|
+
* **deps:** update dependency [@typescript-eslint](https://github.com/typescript-eslint)/eslint-plugin to v6.9.0 ([#753](https://github.com/kelektiv/node-cron/issues/753)) ([9cec04f](https://github.com/kelektiv/node-cron/commit/9cec04f1578f26f50d3e338ad3a9053ef74bbb01))
|
|
23
|
+
|
|
24
|
+
## [3.1.5](https://github.com/kelektiv/node-cron/compare/v3.1.4...v3.1.5) (2023-10-26)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### 🐛 Bug Fixes
|
|
28
|
+
|
|
29
|
+
* detect multiple zeros as an invalid step ([#743](https://github.com/kelektiv/node-cron/issues/743)) [skip ci] ([b0bf677](https://github.com/kelektiv/node-cron/commit/b0bf677ee7b7c322dbe2c9feb13257787edc4fb8))
|
|
30
|
+
* re-add runOnce property to CronJob ([#751](https://github.com/kelektiv/node-cron/issues/751)) ([a61d8c9](https://github.com/kelektiv/node-cron/commit/a61d8c95057b6055a2fe0f18896a098f5d0266e0))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### 📚 Documentation
|
|
34
|
+
|
|
35
|
+
* **readme:** API documentation overhaul ([#716](https://github.com/kelektiv/node-cron/issues/716)) [skip ci] ([23fb0a3](https://github.com/kelektiv/node-cron/commit/23fb0a383fc5dea2f677d69638a1c34ec49b6425))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### ⚙️ Continuous Integrations
|
|
39
|
+
|
|
40
|
+
* **action:** update actions/setup-node action to v4 ([#749](https://github.com/kelektiv/node-cron/issues/749)) ([ef850f3](https://github.com/kelektiv/node-cron/commit/ef850f32f0b429825e2bea59fedbf53fa0053894))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### ♻️ Chores
|
|
44
|
+
|
|
45
|
+
* **deps:** update dependency [@commitlint](https://github.com/commitlint)/cli to v18 ([#747](https://github.com/kelektiv/node-cron/issues/747)) ([5ff1cf8](https://github.com/kelektiv/node-cron/commit/5ff1cf826b376b1c3a03003b771ce8ca96edfaf5))
|
|
46
|
+
* **deps:** update dependency sinon to v17 ([#748](https://github.com/kelektiv/node-cron/issues/748)) ([9d61ff9](https://github.com/kelektiv/node-cron/commit/9d61ff976371ebf93bcfedf8386ba4fe426dcac5))
|
|
47
|
+
* **deps:** update linters ([7bdc726](https://github.com/kelektiv/node-cron/commit/7bdc726e8960d89b489a648eb5918090c7ee01c9))
|
|
48
|
+
* improve ossf scorecard's score ([#715](https://github.com/kelektiv/node-cron/issues/715)) [skip ci] ([1284df4](https://github.com/kelektiv/node-cron/commit/1284df476ec7bbcbc6493ab38af4cb4d3542580b))
|
|
49
|
+
|
|
1
50
|
## [3.1.4](https://github.com/kelektiv/node-cron/compare/v3.1.3...v3.1.4) (2023-10-24)
|
|
2
51
|
|
|
3
52
|
|
package/README.md
CHANGED
|
@@ -1,94 +1,132 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
|
|
2
|
+
<img src="logo.svg" alt="cron for Node.js logo" height="150">
|
|
3
|
+
<br />
|
|
4
|
+
<b>cron</b> is a robust tool for running jobs (functions or commands) on schedules defined using the cron syntax.
|
|
5
|
+
<br />
|
|
6
|
+
Perfect for tasks like data backups, notifications, and many more!
|
|
3
7
|
</p>
|
|
4
8
|
|
|
5
|
-
#
|
|
9
|
+
# Cron for Node.js
|
|
6
10
|
|
|
7
|
-
[](https://badgen.net/npm/dm/cron)
|
|
11
|
+
[](https://www.npmjs.com/package/cron)
|
|
12
|
+
[](https://www.npmjs.com/package/cron)
|
|
13
|
+
[](https://github.com/kelektiv/node-cron/actions/workflows/release.yml)
|
|
14
|
+
[](https://github.com/kelektiv/node-cron/actions/workflows/codeql.yml)
|
|
15
|
+
[](https://app.codecov.io/gh/kelektiv/node-cron)
|
|
16
|
+
[](https://github.com/kelektiv/node-cron/issues/718)
|
|
17
|
+
[](https://securityscorecards.dev/viewer/?uri=github.com/kelektiv/node-cron)
|
|
18
|
+
[](https://discord.gg/yyKns29zch)
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
## 🌟 Features
|
|
18
21
|
|
|
19
22
|
- execute a function whenever your scheduled job triggers
|
|
20
23
|
- execute a job external to the javascript process (like a system command) using `child_process`
|
|
21
24
|
- use a Date or Luxon DateTime object instead of cron syntax as the trigger for your callback
|
|
22
25
|
- use an additional slot for seconds (leaving it off will default to 0 and match the Unix behavior)
|
|
23
26
|
|
|
24
|
-
## Installation
|
|
27
|
+
## 🚀 Installation
|
|
25
28
|
|
|
26
29
|
```bash
|
|
27
30
|
npm install cron
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
##
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
## Table of Contents
|
|
34
|
+
|
|
35
|
+
1. [Features](#-features)
|
|
36
|
+
2. [Installation](#-installation)
|
|
37
|
+
3. [Migrating from v2 to v3](#-migrating-from-v2-to-v3)
|
|
38
|
+
4. [Basic Usage](#-basic-usage)
|
|
39
|
+
5. [Cron Patterns](#cron-patterns)
|
|
40
|
+
- [Cron Syntax Overview](#cron-patterns)
|
|
41
|
+
- [Supported Ranges](#supported-ranges)
|
|
42
|
+
6. [Gotchas](#gotchas)
|
|
43
|
+
7. [API](#api)
|
|
44
|
+
- [Standalone Functions](#standalone-functions)
|
|
45
|
+
- [CronJob Class](#cronjob-class)
|
|
46
|
+
- [CronTime Class](#crontime-class)
|
|
47
|
+
8. [Community](#-community)
|
|
48
|
+
- [Join the Community](#-community)
|
|
49
|
+
9. [Contributing](#-contributing)
|
|
50
|
+
- [General Contribution](#-contributing)
|
|
51
|
+
- [Submitting Bugs/Issues](#-submitting-bugsissues)
|
|
52
|
+
10. [Acknowledgements](#-acknowledgements)
|
|
53
|
+
11. [License](#license)
|
|
54
|
+
|
|
55
|
+
## 🔄 Migrating from v2 to v3
|
|
56
|
+
|
|
57
|
+
With the introduction of TypeScript in version 3 and alignment with UNIX cron patterns, a few changes have been made:
|
|
33
58
|
|
|
34
59
|
<details>
|
|
35
60
|
<summary>Migrating from v2 to v3</summary>
|
|
36
61
|
|
|
37
62
|
### Month & day-of-week indexing changes
|
|
38
63
|
|
|
39
|
-
**Month
|
|
64
|
+
- **Month Indexing:** Changed from `0-11` to `1-12`. So you need to increment all numeric months by 1.
|
|
40
65
|
|
|
41
|
-
|
|
66
|
+
- **Day-of-Week Indexing:** Support added for `7` as Sunday.
|
|
42
67
|
|
|
43
|
-
### CronJob
|
|
68
|
+
### Adjustments in `CronJob`
|
|
44
69
|
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
70
|
+
- The constructor no longer accepts an object as its first and only params. Use `CronJob.from(argsObject)` instead.
|
|
71
|
+
- Callbacks are now called in the order they were registered.
|
|
72
|
+
- `nextDates(count?: number)` now always returns an array (empty if no argument is provided). Use `nextDate()` instead for a single date.
|
|
48
73
|
|
|
49
74
|
### Removed methods
|
|
50
75
|
|
|
51
|
-
-
|
|
76
|
+
- removed `job()` method in favor of `new CronJob(...args)` / `CronJob.from(argsObject)`
|
|
52
77
|
|
|
53
|
-
-
|
|
78
|
+
- removed `time()` method in favor of `new CronTime()`
|
|
54
79
|
|
|
55
80
|
</details>
|
|
56
81
|
|
|
57
|
-
##
|
|
82
|
+
## 🛠 Basic Usage
|
|
58
83
|
|
|
59
84
|
```javascript
|
|
60
85
|
import { CronJob } from 'cron';
|
|
86
|
+
|
|
61
87
|
const job = new CronJob(
|
|
62
|
-
'* * * * * *',
|
|
88
|
+
'* * * * * *', // cronTime
|
|
63
89
|
function () {
|
|
64
90
|
console.log('You will see this message every second');
|
|
65
|
-
},
|
|
66
|
-
null,
|
|
67
|
-
true,
|
|
68
|
-
'America/Los_Angeles'
|
|
91
|
+
}, // onTick
|
|
92
|
+
null, // onComplete
|
|
93
|
+
true, // start
|
|
94
|
+
'America/Los_Angeles' // timeZone
|
|
69
95
|
);
|
|
70
|
-
// job.start()
|
|
96
|
+
// job.start() is optional here because of the fourth parameter set to true.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
// equivalent job using the "from" static method, providing parameters as an object
|
|
101
|
+
const job = CronJob.from({
|
|
102
|
+
cronTime: '* * * * * *',
|
|
103
|
+
onTick: function () {
|
|
104
|
+
console.log('You will see this message every second');
|
|
105
|
+
},
|
|
106
|
+
start: true,
|
|
107
|
+
timeZone: 'America/Los_Angeles'
|
|
108
|
+
});
|
|
71
109
|
```
|
|
72
110
|
|
|
73
|
-
Note
|
|
111
|
+
> **Note:** In the first example above, the fourth parameter to `CronJob()` starts the job automatically. If not provided or set to falsy, you must explicitly start the job using `job.start()`.
|
|
112
|
+
|
|
113
|
+
For more advanced examples, check the [examples directory](https://github.com/kelektiv/node-cron/tree/main/examples).
|
|
74
114
|
|
|
75
|
-
|
|
115
|
+
## Cron Patterns
|
|
76
116
|
|
|
77
|
-
|
|
117
|
+
Cron patterns are the backbone of this library. Familiarize yourself with the syntax:
|
|
78
118
|
|
|
79
119
|
```
|
|
80
|
-
Asterisks
|
|
81
|
-
|
|
82
|
-
Steps
|
|
120
|
+
- `*` Asterisks: Any value
|
|
121
|
+
- `1-3,5` Ranges: Ranges and individual values
|
|
122
|
+
- `*/2` Steps: Every two units
|
|
83
123
|
```
|
|
84
124
|
|
|
85
|
-
|
|
125
|
+
Detailed patterns and explanations are available at [crontab.org](http://crontab.org). The examples in the link have five fields, and 1 minute as the finest granularity, but our cron scheduling supports an enhanced format with six fields, allowing for second-level precision. Tools like [crontab.guru](https://crontab.guru/) can help in constructing patterns but remember to account for the seconds field.
|
|
86
126
|
|
|
87
|
-
|
|
127
|
+
### Supported Ranges
|
|
88
128
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
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.
|
|
129
|
+
Here's a quick reference to the UNIX Cron format this library uses, plus an added second field:
|
|
92
130
|
|
|
93
131
|
```
|
|
94
132
|
field allowed values
|
|
@@ -106,55 +144,101 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
106
144
|
|
|
107
145
|
## Gotchas
|
|
108
146
|
|
|
109
|
-
-
|
|
110
|
-
|
|
147
|
+
- Both JS `Date` and Luxon `DateTime` objects don't guarantee millisecond precision due to computation delays. This module excludes millisecond precision for standard cron syntax but allows execution date specification through JS `Date` or Luxon `DateTime` objects. However, specifying a precise future execution time, such as adding a millisecond to the current time, may not always work due to these computation delays. It's observed that delays less than 4-5 ms might lead to inconsistencies. While we could limit all date granularity to seconds, we've chosen to allow greater precision but advise users of potential issues.
|
|
148
|
+
|
|
149
|
+
- Using arrow functions for `onTick` binds them to the parent's `this` context. As a result, they won't have access to the cronjob's `this` context. You can read a little more in issue [#47 (comment)](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775).
|
|
111
150
|
|
|
112
151
|
## API
|
|
113
152
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
- `sendAt
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
### Standalone Functions
|
|
154
|
+
|
|
155
|
+
- `sendAt`: Indicates when a `CronTime` will execute (returns a Luxon `DateTime` object).
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import * as cron from 'cron';
|
|
159
|
+
|
|
160
|
+
const dt = cron.sendAt('0 0 * * *');
|
|
161
|
+
console.log(`The job would run at: ${dt.toISO()}`);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- `timeout`: Indicates the number of milliseconds in the future at which a `CronTime` will execute (returns a number).
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
import * as cron from 'cron';
|
|
168
|
+
|
|
169
|
+
const timeout = cron.timeout('0 0 * * *');
|
|
170
|
+
console.log(`The job would run in ${timeout}ms`);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### CronJob Class
|
|
174
|
+
|
|
175
|
+
#### Constructor
|
|
176
|
+
|
|
177
|
+
`constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout)`:
|
|
178
|
+
|
|
179
|
+
- `cronTime`: [REQUIRED] - The time to fire off your job. Can be cron syntax, a JS [`Date`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object or a Luxon [`DateTime`](https://moment.github.io/luxon/api-docs/index.html#datetime) object.
|
|
180
|
+
|
|
181
|
+
- `onTick`: [REQUIRED] - Function to execute at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument.
|
|
182
|
+
|
|
183
|
+
- `onComplete`: [OPTIONAL] - Invoked when the job is halted with `job.stop()`. It might also be triggered by `onTick` post its run.
|
|
184
|
+
|
|
185
|
+
- `start`: [OPTIONAL] - Determines if the job should commence before constructor exit. Default is `false`.
|
|
186
|
+
|
|
187
|
+
- `timeZone`: [OPTIONAL] - Sets the execution time zone. Default is local time. Check valid formats in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone).
|
|
188
|
+
|
|
189
|
+
- `context`: [OPTIONAL] - Execution context for the onTick method.
|
|
190
|
+
|
|
191
|
+
- `runOnInit`: [OPTIONAL] - Instantly triggers the `onTick` function post initialization. Default is `false`.
|
|
192
|
+
|
|
193
|
+
- `utcOffset`: [OPTIONAL] - Specifies time zone offset in minutes. Cannot co-exist with `timeZone`.
|
|
194
|
+
|
|
195
|
+
- `unrefTimeout`: [OPTIONAL] - Useful for controlling event loop behavior. More details [here](https://nodejs.org/api/timers.html#timers_timeout_unref).
|
|
196
|
+
|
|
197
|
+
#### Methods
|
|
198
|
+
|
|
199
|
+
- `from` (static): Create a new CronJob object providing arguments as an object. See argument names and descriptions above.
|
|
200
|
+
|
|
201
|
+
- `start`: Initiates the job.
|
|
202
|
+
|
|
203
|
+
- `stop`: Halts the job.
|
|
204
|
+
|
|
205
|
+
- `setTime`: Modifies the time for the `CronJob`. Parameter must be a `CronTime`.
|
|
206
|
+
|
|
207
|
+
- `lastDate`: Provides the last execution date.
|
|
208
|
+
|
|
209
|
+
- `nextDate`: Indicates the subsequent date that will activate an `onTick`.
|
|
210
|
+
|
|
211
|
+
- `nextDates(count)`: Supplies an array of upcoming dates that will initiate an `onTick`.
|
|
212
|
+
|
|
213
|
+
- `fireOnTick`: Allows modification of the `onTick` calling behavior.
|
|
214
|
+
|
|
215
|
+
- `addCallback`: Permits addition of `onTick` callbacks.
|
|
216
|
+
|
|
217
|
+
### CronTime Class
|
|
218
|
+
|
|
219
|
+
#### Constructor
|
|
220
|
+
|
|
221
|
+
`constructor(time, zone, utcOffset)`:
|
|
222
|
+
|
|
223
|
+
- `time`: [REQUIRED] - The time to initiate your job. Accepts cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
|
|
224
|
+
|
|
225
|
+
- `zone`: [OPTIONAL] - Equivalent to `timeZone` from `CronJob` parameters.
|
|
226
|
+
|
|
227
|
+
- `utcOffset`: [OPTIONAL] - Analogous to `utcOffset` from `CronJob` parameters.
|
|
228
|
+
|
|
229
|
+
## 🤝 Community
|
|
146
230
|
|
|
147
231
|
Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss issues and get help in a more casual forum than GitHub.
|
|
148
232
|
|
|
149
|
-
## Contributing
|
|
233
|
+
## 🌍 Contributing
|
|
150
234
|
|
|
151
235
|
This project is looking for help! If you're interested in helping with the project, please take a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md).
|
|
152
236
|
|
|
153
|
-
### Submitting Bugs/Issues
|
|
237
|
+
### 🐛 Submitting Bugs/Issues
|
|
154
238
|
|
|
155
239
|
Please have a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md), it contains all the information you need to know before submitting an issue.
|
|
156
240
|
|
|
157
|
-
## Acknowledgements
|
|
241
|
+
## 🙏 Acknowledgements
|
|
158
242
|
|
|
159
243
|
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.
|
|
160
244
|
|
package/dist/errors.d.ts
CHANGED
package/dist/errors.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExclusiveParametersError = void 0;
|
|
4
|
-
class
|
|
3
|
+
exports.ExclusiveParametersError = exports.CronError = void 0;
|
|
4
|
+
class CronError extends Error {
|
|
5
|
+
}
|
|
6
|
+
exports.CronError = CronError;
|
|
7
|
+
class ExclusiveParametersError extends CronError {
|
|
5
8
|
constructor(param1, param2) {
|
|
6
9
|
super(`You can't specify both ${param1} and ${param2}`);
|
|
7
10
|
}
|
package/dist/job.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
5
5
|
running: boolean;
|
|
6
6
|
unrefTimeout: boolean;
|
|
7
7
|
lastExecution: Date | null;
|
|
8
|
+
runOnce: boolean;
|
|
8
9
|
context: CronContext<C>;
|
|
9
10
|
onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
|
|
10
11
|
private _timeout?;
|
package/dist/job.js
CHANGED
|
@@ -9,6 +9,7 @@ class CronJob {
|
|
|
9
9
|
this.running = false;
|
|
10
10
|
this.unrefTimeout = false;
|
|
11
11
|
this.lastExecution = null;
|
|
12
|
+
this.runOnce = false;
|
|
12
13
|
this._callbacks = [];
|
|
13
14
|
this.context = (context !== null && context !== void 0 ? context : this);
|
|
14
15
|
if (timeZone != null && utcOffset != null) {
|
|
@@ -29,6 +30,9 @@ class CronJob {
|
|
|
29
30
|
if (onComplete != null) {
|
|
30
31
|
this.onComplete = this._fnWrap(onComplete);
|
|
31
32
|
}
|
|
33
|
+
if (this.cronTime.realDate) {
|
|
34
|
+
this.runOnce = true;
|
|
35
|
+
}
|
|
32
36
|
this.addCallback(this._fnWrap(onTick));
|
|
33
37
|
if (runOnInit) {
|
|
34
38
|
this.lastExecution = new Date();
|
|
@@ -73,11 +77,13 @@ class CronJob {
|
|
|
73
77
|
}
|
|
74
78
|
setTime(time) {
|
|
75
79
|
if (!(time instanceof time_1.CronTime)) {
|
|
76
|
-
throw new
|
|
80
|
+
throw new errors_1.CronError('time must be an instance of CronTime.');
|
|
77
81
|
}
|
|
78
82
|
const wasRunning = this.running;
|
|
79
83
|
this.stop();
|
|
80
84
|
this.cronTime = time;
|
|
85
|
+
if (time.realDate)
|
|
86
|
+
this.runOnce = true;
|
|
81
87
|
if (wasRunning)
|
|
82
88
|
this.start();
|
|
83
89
|
}
|
|
@@ -130,7 +136,7 @@ class CronJob {
|
|
|
130
136
|
else {
|
|
131
137
|
this.lastExecution = new Date();
|
|
132
138
|
this.running = false;
|
|
133
|
-
if (!this.
|
|
139
|
+
if (!this.runOnce) {
|
|
134
140
|
this.start();
|
|
135
141
|
}
|
|
136
142
|
this.fireOnTick();
|
package/dist/time.js
CHANGED
|
@@ -20,7 +20,7 @@ class CronTime {
|
|
|
20
20
|
if (timeZone) {
|
|
21
21
|
const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
|
|
22
22
|
if (!dt.isValid) {
|
|
23
|
-
throw new
|
|
23
|
+
throw new errors_1.CronError('Invalid timezone.');
|
|
24
24
|
}
|
|
25
25
|
this.timeZone = timeZone;
|
|
26
26
|
}
|
|
@@ -85,12 +85,12 @@ class CronTime {
|
|
|
85
85
|
const utcZone = `UTC${sign}${offsetHoursStr}:${offsetMinsStr}`;
|
|
86
86
|
date = date.setZone(utcZone);
|
|
87
87
|
if (!date.isValid) {
|
|
88
|
-
throw new
|
|
88
|
+
throw new errors_1.CronError('ERROR: You specified an invalid UTC offset.');
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
if (this.realDate) {
|
|
92
92
|
if (luxon_1.DateTime.local() > date) {
|
|
93
|
-
throw new
|
|
93
|
+
throw new errors_1.CronError('WARNING: Date in past. Will never be fired.');
|
|
94
94
|
}
|
|
95
95
|
return date;
|
|
96
96
|
}
|
|
@@ -133,13 +133,13 @@ class CronTime {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
if (!date.isValid) {
|
|
136
|
-
throw new
|
|
136
|
+
throw new errors_1.CronError('ERROR: You specified an invalid date.');
|
|
137
137
|
}
|
|
138
138
|
const maxMatch = luxon_1.DateTime.now().plus({ years: 8 });
|
|
139
139
|
while (true) {
|
|
140
140
|
const diff = date.toMillis() - start.toMillis();
|
|
141
141
|
if (date > maxMatch) {
|
|
142
|
-
throw new
|
|
142
|
+
throw new errors_1.CronError(`Something went wrong. No execution date was found in the next 8 years.
|
|
143
143
|
Please provide the following string if you would like to help debug:
|
|
144
144
|
Time Zone: ${(_a = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
|
|
145
145
|
}
|
|
@@ -249,7 +249,7 @@ class CronTime {
|
|
|
249
249
|
let iteration = 0;
|
|
250
250
|
do {
|
|
251
251
|
if (++iteration > iterationLimit) {
|
|
252
|
-
throw new
|
|
252
|
+
throw new errors_1.CronError(`ERROR: This DST checking related function assumes the input DateTime (${(_a = date.toISO()) !== null && _a !== void 0 ? _a : date.toMillis()}) is within 24 hours of a DST jump.`);
|
|
253
253
|
}
|
|
254
254
|
expectedMinute = maybeJumpingPoint.minute - 1;
|
|
255
255
|
expectedHour = maybeJumpingPoint.hour;
|
|
@@ -300,7 +300,7 @@ class CronTime {
|
|
|
300
300
|
}
|
|
301
301
|
_checkTimeInSkippedRangeMultiHour(startHour, startMinute, endHour, endMinute) {
|
|
302
302
|
if (startHour >= endHour) {
|
|
303
|
-
throw new
|
|
303
|
+
throw new errors_1.CronError(`ERROR: This DST checking related function assumes the forward jump starting hour (${startHour}) is less than the end hour (${endHour})`);
|
|
304
304
|
}
|
|
305
305
|
const firstHourMinuteRange = Array.from({ length: 60 - startMinute }, (_, k) => startMinute + k);
|
|
306
306
|
const lastHourMinuteRange = Array.from({ length: endMinute }, (_, k) => k);
|
|
@@ -365,14 +365,14 @@ class CronTime {
|
|
|
365
365
|
if (Object.keys(constants_1.ALIASES).includes(alias)) {
|
|
366
366
|
return constants_1.ALIASES[alias].toString();
|
|
367
367
|
}
|
|
368
|
-
throw new
|
|
368
|
+
throw new errors_1.CronError(`Unknown alias: ${alias}`);
|
|
369
369
|
});
|
|
370
370
|
const units = source.trim().split(/\s+/);
|
|
371
371
|
if (units.length < constants_1.TIME_UNITS_LEN - 1) {
|
|
372
|
-
throw new
|
|
372
|
+
throw new errors_1.CronError('Too few fields');
|
|
373
373
|
}
|
|
374
374
|
if (units.length > constants_1.TIME_UNITS_LEN) {
|
|
375
|
-
throw new
|
|
375
|
+
throw new errors_1.CronError('Too many fields');
|
|
376
376
|
}
|
|
377
377
|
const unitsLen = units.length;
|
|
378
378
|
for (const unit of constants_1.TIME_UNITS) {
|
|
@@ -391,7 +391,7 @@ class CronTime {
|
|
|
391
391
|
fields.forEach(field => {
|
|
392
392
|
const wildcardIndex = field.indexOf('*');
|
|
393
393
|
if (wildcardIndex !== -1 && wildcardIndex !== 0) {
|
|
394
|
-
throw new
|
|
394
|
+
throw new errors_1.CronError(`Field (${field}) has an invalid wildcard expression`);
|
|
395
395
|
}
|
|
396
396
|
});
|
|
397
397
|
value = value.replace(constants_1.RE_WILDCARDS, `${low}-${high}`);
|
|
@@ -403,18 +403,18 @@ class CronTime {
|
|
|
403
403
|
let lower = parseInt(mLower, 10);
|
|
404
404
|
let upper = mUpper !== undefined ? parseInt(mUpper, 10) : undefined;
|
|
405
405
|
const wasStepDefined = mStep !== undefined;
|
|
406
|
-
if (mStep === '0') {
|
|
407
|
-
throw new Error(`Field (${unit}) has a step of zero`);
|
|
408
|
-
}
|
|
409
406
|
const step = parseInt(mStep !== null && mStep !== void 0 ? mStep : '1', 10);
|
|
407
|
+
if (step === 0) {
|
|
408
|
+
throw new errors_1.CronError(`Field (${unit}) has a step of zero`);
|
|
409
|
+
}
|
|
410
410
|
if (upper !== undefined && lower > upper) {
|
|
411
|
-
throw new
|
|
411
|
+
throw new errors_1.CronError(`Field (${unit}) has an invalid range`);
|
|
412
412
|
}
|
|
413
413
|
const isOutOfRange = lower < low ||
|
|
414
414
|
(upper !== undefined && upper > high) ||
|
|
415
415
|
(upper === undefined && lower > high);
|
|
416
416
|
if (isOutOfRange) {
|
|
417
|
-
throw new
|
|
417
|
+
throw new errors_1.CronError(`Field value (${value}) is out of range`);
|
|
418
418
|
}
|
|
419
419
|
lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
|
|
420
420
|
if (upper !== undefined) {
|
|
@@ -435,7 +435,7 @@ class CronTime {
|
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
437
|
else {
|
|
438
|
-
throw new
|
|
438
|
+
throw new errors_1.CronError(`Field (${unit}) cannot be parsed`);
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.6",
|
|
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"
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"lint:fix": "npm run lint:eslint -- --fix && npm run lint:prettier -- --write",
|
|
20
20
|
"test": "jest --coverage",
|
|
21
21
|
"test:watch": "jest --watch --coverage",
|
|
22
|
+
"test:fuzz": "jest --testMatch='**/*.fuzz.ts' --coverage=false --testTimeout=120000",
|
|
22
23
|
"prepare": "husky install",
|
|
23
24
|
"release": "semantic-release"
|
|
24
25
|
},
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"luxon": "~3.4.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@commitlint/cli": "
|
|
31
|
+
"@commitlint/cli": "18.2.0",
|
|
32
|
+
"@fast-check/jest": "1.7.3",
|
|
31
33
|
"@insurgentlab/commitlint-config": "18.1.3",
|
|
32
34
|
"@insurgentlab/conventional-changelog-preset": "7.0.0",
|
|
33
35
|
"@semantic-release/changelog": "6.0.3",
|
|
@@ -37,19 +39,19 @@
|
|
|
37
39
|
"@semantic-release/npm": "11.0.0",
|
|
38
40
|
"@semantic-release/release-notes-generator": "12.0.0",
|
|
39
41
|
"@types/jest": "29.5.6",
|
|
40
|
-
"@types/node": "20.8.
|
|
42
|
+
"@types/node": "20.8.9",
|
|
41
43
|
"@types/sinon": "10.0.20",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "6.9.0",
|
|
43
45
|
"chai": "4.3.10",
|
|
44
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.52.0",
|
|
45
47
|
"eslint-config-prettier": "9.0.0",
|
|
46
|
-
"eslint-plugin-jest": "27.4.
|
|
48
|
+
"eslint-plugin-jest": "27.4.3",
|
|
47
49
|
"eslint-plugin-prettier": "5.0.1",
|
|
48
50
|
"husky": "8.0.3",
|
|
49
51
|
"jest": "29.7.0",
|
|
50
52
|
"prettier": "3.0.3",
|
|
51
53
|
"semantic-release": "22.0.5",
|
|
52
|
-
"sinon": "
|
|
54
|
+
"sinon": "17.0.0",
|
|
53
55
|
"ts-jest": "29.1.1",
|
|
54
56
|
"typescript": "5.2.2"
|
|
55
57
|
},
|