cron 4.1.5-beta.1 → 4.2.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 +20 -3
- package/README.md +1 -5
- package/dist/job.d.ts +3 -5
- package/dist/job.js +7 -25
- package/dist/time.js +1 -1
- package/dist/types/cron.types.d.ts +0 -2
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
## [4.
|
|
1
|
+
## [4.2.0](https://github.com/kelektiv/node-cron/compare/v4.1.4...v4.2.0) (2025-04-14)
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### ✨ Features
|
|
4
|
+
|
|
5
|
+
* Allow awaiting job.stop() ([#977](https://github.com/kelektiv/node-cron/issues/977)) ([e296b76](https://github.com/kelektiv/node-cron/commit/e296b76f55783925644ea7d9d10fdfce4172209c)), closes [#976](https://github.com/kelektiv/node-cron/issues/976)
|
|
6
|
+
|
|
7
|
+
### ♻️ Chores
|
|
4
8
|
|
|
5
|
-
*
|
|
9
|
+
* **action:** update github/codeql-action action to v3.28.15 ([baf9c7e](https://github.com/kelektiv/node-cron/commit/baf9c7ef2d0edcbe7ab68c86c42febfc7c662383))
|
|
10
|
+
* **action:** update marocchino/sticky-pull-request-comment action to v2.9.2 ([#975](https://github.com/kelektiv/node-cron/issues/975)) ([df57bef](https://github.com/kelektiv/node-cron/commit/df57befb81f7ea66045663add5919bb169b00b0b))
|
|
11
|
+
* **action:** update step-security/harden-runner action to v2.11.1 ([da1764d](https://github.com/kelektiv/node-cron/commit/da1764d8ff959058f263446de8cc388fe1ef86f6))
|
|
12
|
+
* **deps:** lock file maintenance ([c37a3ec](https://github.com/kelektiv/node-cron/commit/c37a3ec62c96c108146da8affafa733503c2d77c))
|
|
13
|
+
* **deps:** lock file maintenance ([#979](https://github.com/kelektiv/node-cron/issues/979)) ([6a355a3](https://github.com/kelektiv/node-cron/commit/6a355a348f8659494da563cc01ff17fff0e429f0))
|
|
14
|
+
* **deps:** pin dependencies ([6ddc31e](https://github.com/kelektiv/node-cron/commit/6ddc31e6e366fd79bbe9cc49034112414b2dbae3))
|
|
15
|
+
* **deps:** update dependency [@fast-check](https://github.com/fast-check)/jest to v2.1.1 ([3fa6836](https://github.com/kelektiv/node-cron/commit/3fa68364269855f91d0d5b19c99d03df8615c67c))
|
|
16
|
+
* **deps:** update dependency [@swc](https://github.com/swc)/core to v1.11.18 ([00d0685](https://github.com/kelektiv/node-cron/commit/00d06855966939040c66e696327e62e195db516f))
|
|
17
|
+
* **deps:** update dependency [@types](https://github.com/types)/node to v22.14.0 ([7dedc90](https://github.com/kelektiv/node-cron/commit/7dedc9044b23715a2d92ac6cac9552bcbf969641))
|
|
18
|
+
* **deps:** update dependency sinon to v19.0.5 ([448934c](https://github.com/kelektiv/node-cron/commit/448934c42d6592ba5620e65395be7aa153fec099))
|
|
19
|
+
* **deps:** update dependency sinon to v20 ([#974](https://github.com/kelektiv/node-cron/issues/974)) ([ac25eff](https://github.com/kelektiv/node-cron/commit/ac25efff3c4cfae8ca4e4c845812359fcac92d8d))
|
|
20
|
+
* **deps:** update dependency typescript to v5.8.3 ([7b583a4](https://github.com/kelektiv/node-cron/commit/7b583a466f3a8cbb01870a0d1bcd40f5de2af01a))
|
|
21
|
+
* **deps:** update linters ([#978](https://github.com/kelektiv/node-cron/issues/978)) ([cdb638a](https://github.com/kelektiv/node-cron/commit/cdb638a342478573d8276f280236eb3f4902f1ce))
|
|
22
|
+
* **deps:** update node.js to v23.11.0 ([#973](https://github.com/kelektiv/node-cron/issues/973)) ([7d457cf](https://github.com/kelektiv/node-cron/commit/7d457cf34cb2f57c9eec28e46ae35cc8a512e94a))
|
|
6
23
|
|
|
7
24
|
## [4.1.4](https://github.com/kelektiv/node-cron/compare/v4.1.3...v4.1.4) (2025-04-06)
|
|
8
25
|
|
package/README.md
CHANGED
|
@@ -195,7 +195,7 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
195
195
|
|
|
196
196
|
#### Constructor
|
|
197
197
|
|
|
198
|
-
`constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout
|
|
198
|
+
`constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout)`:
|
|
199
199
|
|
|
200
200
|
- `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.
|
|
201
201
|
|
|
@@ -219,10 +219,6 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
219
219
|
|
|
220
220
|
- `errorHandler`: [OPTIONAL] - Function to handle any exceptions that occur in the `onTick` method.
|
|
221
221
|
|
|
222
|
-
- `name`: [OPTIONAL] - Name of the job. Useful for identifying jobs in logs.
|
|
223
|
-
|
|
224
|
-
- `threshold`: [OPTIONAL] - Threshold in ms to control whether to execute or skip missed execution deadlines caused by slow or busy hardware. Execution delays within threshold will be executed immediately, and otherwise will be skipped. In both cases a warning will be printed to the console with the job name and cron expression. See [issue #962](https://github.com/kelektiv/node-cron/issues/962) for more information. Default is `250`.
|
|
225
|
-
|
|
226
222
|
#### Methods
|
|
227
223
|
|
|
228
224
|
- `from` (static): Create a new CronJob object providing arguments as an object. See argument names and descriptions above.
|
package/dist/job.d.ts
CHANGED
|
@@ -9,16 +9,14 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
9
9
|
onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
|
|
10
10
|
waitForCompletion: boolean;
|
|
11
11
|
errorHandler?: CronJobParams<OC, C>['errorHandler'];
|
|
12
|
-
name?: string;
|
|
13
|
-
threshold: number;
|
|
14
12
|
private _isActive;
|
|
15
13
|
private _isCallbackRunning;
|
|
16
14
|
private _timeout?;
|
|
17
15
|
private _callbacks;
|
|
18
16
|
get isActive(): boolean;
|
|
19
17
|
get isCallbackRunning(): boolean;
|
|
20
|
-
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']
|
|
21
|
-
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']
|
|
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']);
|
|
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']);
|
|
22
20
|
static from<OC extends CronOnCompleteCommand | null = null, C = null>(params: CronJobParams<OC, C>): CronJob<OC, C>;
|
|
23
21
|
private _fnWrap;
|
|
24
22
|
addCallback(callback: CronCallback<C, WithOnComplete<OC>>): void;
|
|
@@ -30,5 +28,5 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
30
28
|
lastDate(): Date | null;
|
|
31
29
|
private _executeOnComplete;
|
|
32
30
|
private _waitForJobCompletion;
|
|
33
|
-
stop(): void;
|
|
31
|
+
stop(): Promise<void> | undefined;
|
|
34
32
|
}
|
package/dist/job.js
CHANGED
|
@@ -20,12 +20,11 @@ class CronJob {
|
|
|
20
20
|
get isCallbackRunning() {
|
|
21
21
|
return this._isCallbackRunning;
|
|
22
22
|
}
|
|
23
|
-
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler
|
|
23
|
+
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler) {
|
|
24
24
|
this.unrefTimeout = false;
|
|
25
25
|
this.lastExecution = null;
|
|
26
26
|
this.runOnce = false;
|
|
27
27
|
this.waitForCompletion = false;
|
|
28
|
-
this.threshold = 250;
|
|
29
28
|
this._isActive = false;
|
|
30
29
|
this._isCallbackRunning = false;
|
|
31
30
|
this._callbacks = [];
|
|
@@ -50,12 +49,6 @@ class CronJob {
|
|
|
50
49
|
if (onComplete != null) {
|
|
51
50
|
this.onComplete = this._fnWrap(onComplete);
|
|
52
51
|
}
|
|
53
|
-
if (threshold != null) {
|
|
54
|
-
this.threshold = Math.abs(threshold);
|
|
55
|
-
}
|
|
56
|
-
if (name != null) {
|
|
57
|
-
this.name = name;
|
|
58
|
-
}
|
|
59
52
|
if (this.cronTime.realDate) {
|
|
60
53
|
this.runOnce = true;
|
|
61
54
|
}
|
|
@@ -72,13 +65,13 @@ class CronJob {
|
|
|
72
65
|
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
73
66
|
}
|
|
74
67
|
if (params.timeZone != null) {
|
|
75
|
-
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler
|
|
68
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler);
|
|
76
69
|
}
|
|
77
70
|
else if (params.utcOffset != null) {
|
|
78
|
-
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler
|
|
71
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler);
|
|
79
72
|
}
|
|
80
73
|
else {
|
|
81
|
-
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler
|
|
74
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler);
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
77
|
_fnWrap(cmd) {
|
|
@@ -145,7 +138,6 @@ class CronJob {
|
|
|
145
138
|
start() {
|
|
146
139
|
if (this._isActive)
|
|
147
140
|
return;
|
|
148
|
-
this._isActive = true;
|
|
149
141
|
const MAXDELAY = 2147483647;
|
|
150
142
|
let timeout = this.cronTime.getTimeout();
|
|
151
143
|
let remaining = 0;
|
|
@@ -186,6 +178,7 @@ class CronJob {
|
|
|
186
178
|
}
|
|
187
179
|
};
|
|
188
180
|
if (timeout >= 0) {
|
|
181
|
+
this._isActive = true;
|
|
189
182
|
if (timeout > MAXDELAY) {
|
|
190
183
|
remaining = timeout - MAXDELAY;
|
|
191
184
|
timeout = MAXDELAY;
|
|
@@ -193,18 +186,7 @@ class CronJob {
|
|
|
193
186
|
setCronTimeout(timeout);
|
|
194
187
|
}
|
|
195
188
|
else {
|
|
196
|
-
|
|
197
|
-
const message = `[Cron] Missed execution deadline by ${absoluteTimeout}ms for job${this.name ? ` "${this.name}"` : ''} with cron expression '${String(this.cronTime.source)}'`;
|
|
198
|
-
if (absoluteTimeout <= this.threshold) {
|
|
199
|
-
console.warn(`${message}. Executing immediately.`);
|
|
200
|
-
this.lastExecution = new Date();
|
|
201
|
-
void this.fireOnTick();
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
console.warn(`${message}. Skipping execution as it exceeds threshold (${this.threshold}ms).`);
|
|
205
|
-
}
|
|
206
|
-
timeout = this.cronTime.getTimeout();
|
|
207
|
-
setCronTimeout(timeout);
|
|
189
|
+
this.stop();
|
|
208
190
|
}
|
|
209
191
|
}
|
|
210
192
|
lastDate() {
|
|
@@ -237,7 +219,7 @@ class CronJob {
|
|
|
237
219
|
void this._executeOnComplete();
|
|
238
220
|
return;
|
|
239
221
|
}
|
|
240
|
-
|
|
222
|
+
return Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
|
|
241
223
|
yield this._waitForJobCompletion();
|
|
242
224
|
yield this._executeOnComplete();
|
|
243
225
|
}));
|
package/dist/time.js
CHANGED
|
@@ -96,7 +96,7 @@ class CronTime {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
getTimeout() {
|
|
99
|
-
return this.sendAt().toMillis() - luxon_1.DateTime.
|
|
99
|
+
return Math.max(-1, this.sendAt().toMillis() - luxon_1.DateTime.utc().toMillis());
|
|
100
100
|
}
|
|
101
101
|
toString() {
|
|
102
102
|
return this.toJSON().join(' ');
|
|
@@ -13,8 +13,6 @@ interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
13
13
|
unrefTimeout?: boolean | null;
|
|
14
14
|
waitForCompletion?: boolean | null;
|
|
15
15
|
errorHandler?: ((error: unknown) => void) | null;
|
|
16
|
-
threshold?: number | null;
|
|
17
|
-
name?: string | null;
|
|
18
16
|
}
|
|
19
17
|
export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> & ({
|
|
20
18
|
timeZone?: string | null;
|
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.
|
|
4
|
+
"version": "4.2.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"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@commitlint/cli": "19.8.0",
|
|
32
|
-
"@eslint/js": "9.
|
|
33
|
-
"@fast-check/jest": "2.1.
|
|
32
|
+
"@eslint/js": "9.24.0",
|
|
33
|
+
"@fast-check/jest": "2.1.1",
|
|
34
34
|
"@insurgent/commitlint-config": "20.0.0",
|
|
35
35
|
"@insurgent/conventional-changelog-preset": "10.0.0",
|
|
36
36
|
"@semantic-release/changelog": "6.0.3",
|
|
@@ -39,24 +39,24 @@
|
|
|
39
39
|
"@semantic-release/github": "11.0.1",
|
|
40
40
|
"@semantic-release/npm": "12.0.1",
|
|
41
41
|
"@semantic-release/release-notes-generator": "14.0.3",
|
|
42
|
-
"@swc/core": "
|
|
43
|
-
"@swc/jest": "
|
|
42
|
+
"@swc/core": "1.11.18",
|
|
43
|
+
"@swc/jest": "0.2.37",
|
|
44
44
|
"@types/jest": "29.5.14",
|
|
45
|
-
"@types/node": "22.
|
|
45
|
+
"@types/node": "22.14.0",
|
|
46
46
|
"@types/sinon": "17.0.4",
|
|
47
47
|
"chai": "5.2.0",
|
|
48
48
|
"cross-env": "7.0.3",
|
|
49
49
|
"eslint": "8.57.1",
|
|
50
50
|
"eslint-config-prettier": "9.1.0",
|
|
51
51
|
"eslint-plugin-jest": "27.9.0",
|
|
52
|
-
"eslint-plugin-prettier": "5.2.
|
|
52
|
+
"eslint-plugin-prettier": "5.2.6",
|
|
53
53
|
"husky": "9.1.7",
|
|
54
54
|
"jest": "29.7.0",
|
|
55
55
|
"lint-staged": "15.5.0",
|
|
56
56
|
"prettier": "3.5.3",
|
|
57
57
|
"semantic-release": "24.2.3",
|
|
58
|
-
"sinon": "
|
|
59
|
-
"typescript": "5.8.
|
|
58
|
+
"sinon": "20.0.0",
|
|
59
|
+
"typescript": "5.8.3",
|
|
60
60
|
"typescript-eslint": "7.18.0"
|
|
61
61
|
},
|
|
62
62
|
"keywords": [
|