cron 3.5.0 → 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 +21 -0
- package/README.md +36 -19
- package/dist/job.d.ts +2 -1
- package/dist/job.js +9 -6
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [4.0.0](https://github.com/kelektiv/node-cron/compare/v3.5.0...v4.0.0) (2025-02-19)
|
|
2
|
+
|
|
3
|
+
### ⚠ Breaking changes
|
|
4
|
+
|
|
5
|
+
* drop support for Node v16 and rename job.running to job.isActive (#957)
|
|
6
|
+
|
|
7
|
+
### 📦 Code Refactoring
|
|
8
|
+
|
|
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)
|
|
10
|
+
|
|
11
|
+
### ♻️ Chores
|
|
12
|
+
|
|
13
|
+
* **action:** update actions/checkout action to v4.2.2 ([#927](https://github.com/kelektiv/node-cron/issues/927)) ([ff1721e](https://github.com/kelektiv/node-cron/commit/ff1721e95f1a0d7291f3809dd89af8a0956b8f7f))
|
|
14
|
+
* **action:** update actions/setup-node action to v4.1.0 ([#928](https://github.com/kelektiv/node-cron/issues/928)) ([3e27773](https://github.com/kelektiv/node-cron/commit/3e277738b4a5d096f5990602c3d7aaff02f5961c))
|
|
15
|
+
* **action:** update actions/upload-artifact action to v4.6.0 ([#931](https://github.com/kelektiv/node-cron/issues/931)) ([8283000](https://github.com/kelektiv/node-cron/commit/82830003bcb375b55ae86b2038305af69f587d33))
|
|
16
|
+
* **action:** update amannn/action-semantic-pull-request action to v5.5.3 ([#929](https://github.com/kelektiv/node-cron/issues/929)) ([f1851d7](https://github.com/kelektiv/node-cron/commit/f1851d7d3f4780ef7f6834f35999f93cae5961cf))
|
|
17
|
+
* **action:** update github/codeql-action action to v3.28.1 ([#922](https://github.com/kelektiv/node-cron/issues/922)) ([eefd476](https://github.com/kelektiv/node-cron/commit/eefd47698bad8da9c9cad15fba9ecc0925b95f49))
|
|
18
|
+
* **deps:** lock file maintenance ([c3af5fc](https://github.com/kelektiv/node-cron/commit/c3af5fc439b822683377abea4a7e957ee7743c5c))
|
|
19
|
+
* **deps:** lock file maintenance ([d689a1c](https://github.com/kelektiv/node-cron/commit/d689a1c489f9576de49da8ee8489cbaf700be3c3))
|
|
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))
|
|
21
|
+
|
|
1
22
|
## [3.5.0](https://github.com/kelektiv/node-cron/compare/v3.4.0...v3.5.0) (2025-01-10)
|
|
2
23
|
|
|
3
24
|
### ✨ Features
|
package/README.md
CHANGED
|
@@ -34,27 +34,42 @@ npm install cron
|
|
|
34
34
|
|
|
35
35
|
1. [Features](#-features)
|
|
36
36
|
2. [Installation](#-installation)
|
|
37
|
-
3. [Migrating
|
|
37
|
+
3. [Migrating](#-migrating)
|
|
38
38
|
4. [Basic Usage](#-basic-usage)
|
|
39
|
-
5. [Cron Patterns](
|
|
40
|
-
- [Cron Syntax Overview](
|
|
39
|
+
5. [Cron Patterns](#-cron-patterns)
|
|
40
|
+
- [Cron Syntax Overview](#-cron-patterns)
|
|
41
41
|
- [Supported Ranges](#supported-ranges)
|
|
42
|
-
6. [
|
|
43
|
-
7. [API](#api)
|
|
42
|
+
6. [API](#-api)
|
|
44
43
|
- [Standalone Functions](#standalone-functions)
|
|
45
44
|
- [CronJob Class](#cronjob-class)
|
|
46
45
|
- [CronTime Class](#crontime-class)
|
|
46
|
+
7. [Gotchas](#-gotchas)
|
|
47
47
|
8. [Community](#-community)
|
|
48
48
|
- [Join the Community](#-community)
|
|
49
49
|
9. [Contributing](#-contributing)
|
|
50
50
|
- [General Contribution](#-contributing)
|
|
51
51
|
- [Submitting Bugs/Issues](#-submitting-bugsissues)
|
|
52
52
|
10. [Acknowledgements](#-acknowledgements)
|
|
53
|
-
11. [License](
|
|
53
|
+
11. [License](#-license)
|
|
54
54
|
|
|
55
|
-
##
|
|
55
|
+
## ⬆ Migrating
|
|
56
56
|
|
|
57
|
-
|
|
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:
|
|
58
73
|
|
|
59
74
|
<details>
|
|
60
75
|
<summary>Migrating from v2 to v3</summary>
|
|
@@ -112,7 +127,7 @@ const job = CronJob.from({
|
|
|
112
127
|
|
|
113
128
|
For more advanced examples, check the [examples directory](https://github.com/kelektiv/node-cron/tree/main/examples).
|
|
114
129
|
|
|
115
|
-
## Cron Patterns
|
|
130
|
+
## ⏰ Cron Patterns
|
|
116
131
|
|
|
117
132
|
Cron patterns are the backbone of this library. Familiarize yourself with the syntax:
|
|
118
133
|
|
|
@@ -142,13 +157,7 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
142
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.
|
|
143
158
|
> Examples: "mon,wed,fri", "jan-mar".
|
|
144
159
|
|
|
145
|
-
##
|
|
146
|
-
|
|
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).
|
|
150
|
-
|
|
151
|
-
## API
|
|
160
|
+
## 📖 API
|
|
152
161
|
|
|
153
162
|
### Standalone Functions
|
|
154
163
|
|
|
@@ -220,6 +229,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
220
229
|
|
|
221
230
|
#### Properties
|
|
222
231
|
|
|
232
|
+
- `isActive`: [READ-ONLY] Indicates if a job is active (checking to see if the callback needs to be called).
|
|
233
|
+
|
|
223
234
|
- `isCallbackRunning`: [READ-ONLY] Indicates if a callback is currently executing.
|
|
224
235
|
|
|
225
236
|
```javascript
|
|
@@ -231,8 +242,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
231
242
|
|
|
232
243
|
console.log(job.isCallbackRunning); // false
|
|
233
244
|
job.start();
|
|
234
|
-
console.log(job.
|
|
235
|
-
console.log(job.isCallbackRunning); // false
|
|
245
|
+
console.log(job.isActive); // true
|
|
246
|
+
console.log(job.isCallbackRunning); // false
|
|
236
247
|
```
|
|
237
248
|
|
|
238
249
|
### CronTime Class
|
|
@@ -247,6 +258,12 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
247
258
|
|
|
248
259
|
- `utcOffset`: [OPTIONAL] - Analogous to `utcOffset` from `CronJob` parameters.
|
|
249
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
|
+
|
|
250
267
|
## 🤝 Community
|
|
251
268
|
|
|
252
269
|
Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss issues and get help in a more casual forum than GitHub.
|
|
@@ -265,6 +282,6 @@ This is a community effort project. In the truest sense, this project started as
|
|
|
265
282
|
|
|
266
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.
|
|
267
284
|
|
|
268
|
-
## License
|
|
285
|
+
## ⚖ License
|
|
269
286
|
|
|
270
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;
|
|
@@ -211,7 +214,7 @@ class CronJob {
|
|
|
211
214
|
stop() {
|
|
212
215
|
if (this._timeout)
|
|
213
216
|
clearTimeout(this._timeout);
|
|
214
|
-
this.
|
|
217
|
+
this._isActive = false;
|
|
215
218
|
if (!this.waitForCompletion) {
|
|
216
219
|
void this._executeOnComplete();
|
|
217
220
|
return;
|
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",
|