cron 3.5.1-beta.1 → 4.0.0
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 +7 -13
- package/README.md +36 -24
- package/dist/job.d.ts +2 -1
- package/dist/job.js +10 -20
- package/dist/time.js +1 -1
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [4.0.0](https://github.com/kelektiv/node-cron/compare/v3.5.0...v4.0.0) (2025-02-19)
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### ⚠ Breaking changes
|
|
4
|
+
|
|
5
|
+
* drop support for Node v16 and rename job.running to job.isActive (#957)
|
|
6
|
+
|
|
7
|
+
### 📦 Code Refactoring
|
|
4
8
|
|
|
5
|
-
*
|
|
9
|
+
* drop support for Node v16 and rename job.running to job.isActive ([#957](https://github.com/kelektiv/node-cron/issues/957)) ([605e94e](https://github.com/kelektiv/node-cron/commit/605e94ef3b6469caf2e8526d0935014eea8804c8)), closes [#902](https://github.com/kelektiv/node-cron/issues/902) [#905](https://github.com/kelektiv/node-cron/issues/905)
|
|
6
10
|
|
|
7
11
|
### ♻️ Chores
|
|
8
12
|
|
|
@@ -14,7 +18,6 @@
|
|
|
14
18
|
* **deps:** lock file maintenance ([c3af5fc](https://github.com/kelektiv/node-cron/commit/c3af5fc439b822683377abea4a7e957ee7743c5c))
|
|
15
19
|
* **deps:** lock file maintenance ([d689a1c](https://github.com/kelektiv/node-cron/commit/d689a1c489f9576de49da8ee8489cbaf700be3c3))
|
|
16
20
|
* **renovate:** improve schedules & automerging to reduce noise ([#942](https://github.com/kelektiv/node-cron/issues/942)) ([c253032](https://github.com/kelektiv/node-cron/commit/c253032d520edd09f29e111fa181f4977a7f9d53))
|
|
17
|
-
* **runtime:** dirty Node 16 drop, don't cherry-pick ([d6815f3](https://github.com/kelektiv/node-cron/commit/d6815f3ff94799f8157b8ee8daae1897d3fa0cf2))
|
|
18
21
|
|
|
19
22
|
## [3.5.0](https://github.com/kelektiv/node-cron/compare/v3.4.0...v3.5.0) (2025-01-10)
|
|
20
23
|
|
|
@@ -55,12 +58,6 @@
|
|
|
55
58
|
|
|
56
59
|
* fix infinite loop on expressions resolving only inside a DST forward jump ([#938](https://github.com/kelektiv/node-cron/issues/938)) ([efb8df5](https://github.com/kelektiv/node-cron/commit/efb8df53405b4ce2ea2e70be9e4d90c124616a51)), closes [/github.com/kelektiv/node-cron/pull/667/files#diff-c14c2dca8456f15417b39cfbd9758009f8eb4f3a190a415768d6e4ae6ae9dceeL473-L477](https://github.com/kelektiv//github.com/kelektiv/node-cron/pull/667/files/issues/diff-c14c2dca8456f15417b39cfbd9758009f8eb4f3a190a415768d6e4ae6ae9dceeL473-L477) [#919](https://github.com/kelektiv/node-cron/issues/919) [#919](https://github.com/kelektiv/node-cron/issues/919)
|
|
57
60
|
|
|
58
|
-
## [3.3.2-beta.1](https://github.com/kelektiv/node-cron/compare/v3.3.1...v3.3.2-beta.1) (2024-12-27)
|
|
59
|
-
|
|
60
|
-
### 🐛 Bug Fixes
|
|
61
|
-
|
|
62
|
-
* attempt to fix [#805](https://github.com/kelektiv/node-cron/issues/805) ([187dbe5](https://github.com/kelektiv/node-cron/commit/187dbe57ada28217b810b231bf57afdfe3a3b394))
|
|
63
|
-
|
|
64
61
|
### ⚙️ Continuous Integrations
|
|
65
62
|
|
|
66
63
|
* **action:** update marocchino/sticky-pull-request-comment action to v2.9.0 ([#930](https://github.com/kelektiv/node-cron/issues/930)) ([1e7bce9](https://github.com/kelektiv/node-cron/commit/1e7bce9d12a774104f39c1d75b37bdb134e4b270))
|
|
@@ -68,10 +65,7 @@
|
|
|
68
65
|
|
|
69
66
|
### ♻️ Chores
|
|
70
67
|
|
|
71
|
-
<<<<<<< HEAD
|
|
72
|
-
=======
|
|
73
68
|
* **deps:** lock file maintenance ([70c3339](https://github.com/kelektiv/node-cron/commit/70c333955612d39b692ab9535b36fe33423eb593))
|
|
74
|
-
>>>>>>> main
|
|
75
69
|
* **deps:** lock file maintenance ([afad454](https://github.com/kelektiv/node-cron/commit/afad454e5e4f52e3da54965a0e10540e035c4f58))
|
|
76
70
|
* **deps:** lock file maintenance ([b1dbf69](https://github.com/kelektiv/node-cron/commit/b1dbf69104a58022a638d5b68b59f85089fae7c6))
|
|
77
71
|
* **deps:** pin dependencies ([#915](https://github.com/kelektiv/node-cron/issues/915)) ([dfcbd3c](https://github.com/kelektiv/node-cron/commit/dfcbd3cf7d901415bda5b4929566bd4ad527af62))
|
package/README.md
CHANGED
|
@@ -6,11 +6,6 @@
|
|
|
6
6
|
Perfect for tasks like data backups, notifications, and many more!
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
> **⚠️ WARNING**
|
|
10
|
-
>
|
|
11
|
-
> This is a WIP released as beta for testing purposes.
|
|
12
|
-
> For more information, please refer to [issue #805](https://github.com/kelektiv/node-cron/issues/805).
|
|
13
|
-
|
|
14
9
|
# Cron for Node.js
|
|
15
10
|
|
|
16
11
|
[](https://www.npmjs.com/package/cron)
|
|
@@ -39,27 +34,42 @@ npm install cron
|
|
|
39
34
|
|
|
40
35
|
1. [Features](#-features)
|
|
41
36
|
2. [Installation](#-installation)
|
|
42
|
-
3. [Migrating
|
|
37
|
+
3. [Migrating](#-migrating)
|
|
43
38
|
4. [Basic Usage](#-basic-usage)
|
|
44
|
-
5. [Cron Patterns](
|
|
45
|
-
- [Cron Syntax Overview](
|
|
39
|
+
5. [Cron Patterns](#-cron-patterns)
|
|
40
|
+
- [Cron Syntax Overview](#-cron-patterns)
|
|
46
41
|
- [Supported Ranges](#supported-ranges)
|
|
47
|
-
6. [
|
|
48
|
-
7. [API](#api)
|
|
42
|
+
6. [API](#-api)
|
|
49
43
|
- [Standalone Functions](#standalone-functions)
|
|
50
44
|
- [CronJob Class](#cronjob-class)
|
|
51
45
|
- [CronTime Class](#crontime-class)
|
|
46
|
+
7. [Gotchas](#-gotchas)
|
|
52
47
|
8. [Community](#-community)
|
|
53
48
|
- [Join the Community](#-community)
|
|
54
49
|
9. [Contributing](#-contributing)
|
|
55
50
|
- [General Contribution](#-contributing)
|
|
56
51
|
- [Submitting Bugs/Issues](#-submitting-bugsissues)
|
|
57
52
|
10. [Acknowledgements](#-acknowledgements)
|
|
58
|
-
11. [License](
|
|
53
|
+
11. [License](#-license)
|
|
59
54
|
|
|
60
|
-
##
|
|
55
|
+
## ⬆ Migrating
|
|
61
56
|
|
|
62
|
-
|
|
57
|
+
v4 dropped Node v16 and renamed the `job.running` property:
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary>Migrating from v3 to v4</summary>
|
|
61
|
+
|
|
62
|
+
### Dropped Node version
|
|
63
|
+
|
|
64
|
+
Node v16 is no longer supported. Upgrade your Node installation to Node v18 or above
|
|
65
|
+
|
|
66
|
+
### Property renamed and now read-only
|
|
67
|
+
|
|
68
|
+
You can no longer set the `running` property (now `isActive`). It is read-only. To start or stop a cron job, use `job.start()` and `job.stop()`.
|
|
69
|
+
|
|
70
|
+
</details>
|
|
71
|
+
|
|
72
|
+
v3 introduced TypeScript and tighter Unix cron pattern alignment:
|
|
63
73
|
|
|
64
74
|
<details>
|
|
65
75
|
<summary>Migrating from v2 to v3</summary>
|
|
@@ -117,7 +127,7 @@ const job = CronJob.from({
|
|
|
117
127
|
|
|
118
128
|
For more advanced examples, check the [examples directory](https://github.com/kelektiv/node-cron/tree/main/examples).
|
|
119
129
|
|
|
120
|
-
## Cron Patterns
|
|
130
|
+
## ⏰ Cron Patterns
|
|
121
131
|
|
|
122
132
|
Cron patterns are the backbone of this library. Familiarize yourself with the syntax:
|
|
123
133
|
|
|
@@ -147,13 +157,7 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
147
157
|
> 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.
|
|
148
158
|
> Examples: "mon,wed,fri", "jan-mar".
|
|
149
159
|
|
|
150
|
-
##
|
|
151
|
-
|
|
152
|
-
- 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.
|
|
153
|
-
|
|
154
|
-
- 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).
|
|
155
|
-
|
|
156
|
-
## API
|
|
160
|
+
## 📖 API
|
|
157
161
|
|
|
158
162
|
### Standalone Functions
|
|
159
163
|
|
|
@@ -225,6 +229,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
225
229
|
|
|
226
230
|
#### Properties
|
|
227
231
|
|
|
232
|
+
- `isActive`: [READ-ONLY] Indicates if a job is active (checking to see if the callback needs to be called).
|
|
233
|
+
|
|
228
234
|
- `isCallbackRunning`: [READ-ONLY] Indicates if a callback is currently executing.
|
|
229
235
|
|
|
230
236
|
```javascript
|
|
@@ -236,8 +242,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
236
242
|
|
|
237
243
|
console.log(job.isCallbackRunning); // false
|
|
238
244
|
job.start();
|
|
239
|
-
console.log(job.
|
|
240
|
-
console.log(job.isCallbackRunning); // false
|
|
245
|
+
console.log(job.isActive); // true
|
|
246
|
+
console.log(job.isCallbackRunning); // false
|
|
241
247
|
```
|
|
242
248
|
|
|
243
249
|
### CronTime Class
|
|
@@ -252,6 +258,12 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
252
258
|
|
|
253
259
|
- `utcOffset`: [OPTIONAL] - Analogous to `utcOffset` from `CronJob` parameters.
|
|
254
260
|
|
|
261
|
+
## 💢 Gotchas
|
|
262
|
+
|
|
263
|
+
- 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.
|
|
264
|
+
|
|
265
|
+
- 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).
|
|
266
|
+
|
|
255
267
|
## 🤝 Community
|
|
256
268
|
|
|
257
269
|
Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss issues and get help in a more casual forum than GitHub.
|
|
@@ -270,6 +282,6 @@ This is a community effort project. In the truest sense, this project started as
|
|
|
270
282
|
|
|
271
283
|
Special thanks to [Hiroki Horiuchi](https://github.com/horiuchi), [Lundarl Gholoi](https://github.com/winup) and [koooge](https://github.com/koooge) for their work on the [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) typings before they were imported in v2.4.0.
|
|
272
284
|
|
|
273
|
-
## License
|
|
285
|
+
## ⚖ License
|
|
274
286
|
|
|
275
287
|
MIT
|
package/dist/job.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { CronTime } from './time';
|
|
|
2
2
|
import { CronCallback, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, WithOnComplete } from './types/cron.types';
|
|
3
3
|
export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C = null> {
|
|
4
4
|
cronTime: CronTime;
|
|
5
|
-
running: boolean;
|
|
6
5
|
unrefTimeout: boolean;
|
|
7
6
|
lastExecution: Date | null;
|
|
8
7
|
runOnce: boolean;
|
|
@@ -10,9 +9,11 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
10
9
|
onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
|
|
11
10
|
waitForCompletion: boolean;
|
|
12
11
|
errorHandler?: CronJobParams<OC, C>['errorHandler'];
|
|
12
|
+
private _isActive;
|
|
13
13
|
private _isCallbackRunning;
|
|
14
14
|
private _timeout?;
|
|
15
15
|
private _callbacks;
|
|
16
|
+
get isActive(): boolean;
|
|
16
17
|
get isCallbackRunning(): boolean;
|
|
17
18
|
constructor(cronTime: CronJobParams<OC, C>['cronTime'], onTick: CronJobParams<OC, C>['onTick'], onComplete?: CronJobParams<OC, C>['onComplete'], start?: CronJobParams<OC, C>['start'], timeZone?: CronJobParams<OC, C>['timeZone'], context?: CronJobParams<OC, C>['context'], runOnInit?: CronJobParams<OC, C>['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams<OC, C>['unrefTimeout'], waitForCompletion?: CronJobParams<OC, C>['waitForCompletion'], errorHandler?: CronJobParams<OC, C>['errorHandler']);
|
|
18
19
|
constructor(cronTime: CronJobParams<OC, C>['cronTime'], onTick: CronJobParams<OC, C>['onTick'], onComplete?: CronJobParams<OC, C>['onComplete'], start?: CronJobParams<OC, C>['start'], timeZone?: null, context?: CronJobParams<OC, C>['context'], runOnInit?: CronJobParams<OC, C>['runOnInit'], utcOffset?: CronJobParams<OC, C>['utcOffset'], unrefTimeout?: CronJobParams<OC, C>['unrefTimeout'], waitForCompletion?: CronJobParams<OC, C>['waitForCompletion'], errorHandler?: CronJobParams<OC, C>['errorHandler']);
|
package/dist/job.js
CHANGED
|
@@ -14,15 +14,18 @@ const child_process_1 = require("child_process");
|
|
|
14
14
|
const errors_1 = require("./errors");
|
|
15
15
|
const time_1 = require("./time");
|
|
16
16
|
class CronJob {
|
|
17
|
+
get isActive() {
|
|
18
|
+
return this._isActive;
|
|
19
|
+
}
|
|
17
20
|
get isCallbackRunning() {
|
|
18
21
|
return this._isCallbackRunning;
|
|
19
22
|
}
|
|
20
23
|
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler) {
|
|
21
|
-
this.running = false;
|
|
22
24
|
this.unrefTimeout = false;
|
|
23
25
|
this.lastExecution = null;
|
|
24
26
|
this.runOnce = false;
|
|
25
27
|
this.waitForCompletion = false;
|
|
28
|
+
this._isActive = false;
|
|
26
29
|
this._isCallbackRunning = false;
|
|
27
30
|
this._callbacks = [];
|
|
28
31
|
this.context = (context !== null && context !== void 0 ? context : this);
|
|
@@ -95,7 +98,7 @@ class CronJob {
|
|
|
95
98
|
if (!(time instanceof time_1.CronTime)) {
|
|
96
99
|
throw new errors_1.CronError('time must be an instance of CronTime.');
|
|
97
100
|
}
|
|
98
|
-
const wasRunning = this.
|
|
101
|
+
const wasRunning = this._isActive;
|
|
99
102
|
this.stop();
|
|
100
103
|
this.cronTime = time;
|
|
101
104
|
if (time.realDate)
|
|
@@ -133,7 +136,7 @@ class CronJob {
|
|
|
133
136
|
return this.cronTime.sendAt(i !== null && i !== void 0 ? i : 0);
|
|
134
137
|
}
|
|
135
138
|
start() {
|
|
136
|
-
if (this.
|
|
139
|
+
if (this._isActive)
|
|
137
140
|
return;
|
|
138
141
|
const MAXDELAY = 2147483647;
|
|
139
142
|
let timeout = this.cronTime.getTimeout();
|
|
@@ -168,14 +171,14 @@ class CronJob {
|
|
|
168
171
|
}
|
|
169
172
|
else {
|
|
170
173
|
this.lastExecution = new Date();
|
|
171
|
-
this.
|
|
174
|
+
this._isActive = false;
|
|
172
175
|
if (!this.runOnce)
|
|
173
176
|
this.start();
|
|
174
177
|
void this.fireOnTick();
|
|
175
178
|
}
|
|
176
179
|
};
|
|
177
180
|
if (timeout >= 0) {
|
|
178
|
-
this.
|
|
181
|
+
this._isActive = true;
|
|
179
182
|
if (timeout > MAXDELAY) {
|
|
180
183
|
remaining = timeout - MAXDELAY;
|
|
181
184
|
timeout = MAXDELAY;
|
|
@@ -183,20 +186,7 @@ class CronJob {
|
|
|
183
186
|
setCronTimeout(timeout);
|
|
184
187
|
}
|
|
185
188
|
else {
|
|
186
|
-
|
|
187
|
-
console.warn(`[CRON DEBUG] Executing job with a delay: ${timeout}ms`);
|
|
188
|
-
this.lastExecution = new Date();
|
|
189
|
-
this.running = false;
|
|
190
|
-
if (!this.runOnce)
|
|
191
|
-
this.start();
|
|
192
|
-
void this.fireOnTick();
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
console.error(`[CRON DEBUG] Stopping job due to delay being higher than 1s: ${timeout}ms`);
|
|
196
|
-
this.stop();
|
|
197
|
-
}
|
|
198
|
-
console.debug(`[CRON DEBUG] Current date: ${new Date().toISOString()}`);
|
|
199
|
-
console.debug(`[CRON DEBUG] Source: ${String(this.cronTime.source)}`);
|
|
189
|
+
this.stop();
|
|
200
190
|
}
|
|
201
191
|
}
|
|
202
192
|
lastDate() {
|
|
@@ -224,7 +214,7 @@ class CronJob {
|
|
|
224
214
|
stop() {
|
|
225
215
|
if (this._timeout)
|
|
226
216
|
clearTimeout(this._timeout);
|
|
227
|
-
this.
|
|
217
|
+
this._isActive = false;
|
|
228
218
|
if (!this.waitForCompletion) {
|
|
229
219
|
void this._executeOnComplete();
|
|
230
220
|
return;
|
package/dist/time.js
CHANGED
|
@@ -77,7 +77,7 @@ class CronTime {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
getTimeout() {
|
|
80
|
-
return this.sendAt().toMillis() - luxon_1.DateTime.local().toMillis();
|
|
80
|
+
return Math.max(-1, this.sendAt().toMillis() - luxon_1.DateTime.local().toMillis());
|
|
81
81
|
}
|
|
82
82
|
toString() {
|
|
83
83
|
return this.toJSON().join(' ');
|
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": "4.0.0",
|
|
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"
|
|
@@ -85,6 +85,9 @@
|
|
|
85
85
|
"Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)",
|
|
86
86
|
"Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"
|
|
87
87
|
],
|
|
88
|
+
"engines": {
|
|
89
|
+
"node": ">=18.x"
|
|
90
|
+
},
|
|
88
91
|
"files": [
|
|
89
92
|
"dist/**/*.js",
|
|
90
93
|
"dist/**/*.d.ts",
|