cron 5.0.0-beta.3 → 5.0.0-beta.4
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 +14 -0
- package/README.md +1 -1
- package/dist/job.js +64 -73
- package/dist/time.js +17 -16
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [5.0.0-beta.4](https://github.com/kelektiv/node-cron/compare/v5.0.0-beta.3...v5.0.0-beta.4) (2026-11-24)
|
|
2
|
+
|
|
3
|
+
### 🛠 Builds
|
|
4
|
+
|
|
5
|
+
* fix tsconfig issues ([e53ffa9](https://github.com/kelektiv/node-cron/commit/e53ffa9aad7d8ccd72b7af446dc29ed9c5eccec3))
|
|
6
|
+
|
|
7
|
+
### 📦 Code Refactoring
|
|
8
|
+
|
|
9
|
+
* tests should use the .from method to create CronJob objects ([#1107](https://github.com/kelektiv/node-cron/issues/1107)) ([880c473](https://github.com/kelektiv/node-cron/commit/880c473bcdc2b67baee40f405be188527e8ca0fa))
|
|
10
|
+
|
|
11
|
+
### ♻️ Chores
|
|
12
|
+
|
|
13
|
+
* **deps:** bump luxon version ([5a6b262](https://github.com/kelektiv/node-cron/commit/5a6b2627a33b71af0f6c3a221db1b0d399738857))
|
|
14
|
+
|
|
1
15
|
## [5.0.0-beta.3](https://github.com/kelektiv/node-cron/compare/v5.0.0-beta.2...v5.0.0-beta.3) (2026-11-24)
|
|
2
16
|
|
|
3
17
|
### 🐛 Bug Fixes
|
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ const job = new CronJob('* * * * * *', function () {
|
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
While this method is still officially supported (any bugs or security issues will be fixed) it is deprecated and no longer recommended. You will get a warning that support will be dropped in the next major version of Cron.
|
|
75
|
+
While this method is still officially supported (any bugs or security issues with it will be fixed) it is deprecated and no longer recommended. You will get a warning that support will be dropped in the next major version of Cron.
|
|
76
76
|
|
|
77
77
|
Instead, create `CronJob` objects like this:
|
|
78
78
|
|
package/dist/job.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.CronJob = void 0;
|
|
13
4
|
const errors_1 = require("./errors");
|
|
14
5
|
const time_1 = require("./time");
|
|
15
6
|
class CronJob {
|
|
7
|
+
cronTime;
|
|
8
|
+
unrefTimeout = false;
|
|
9
|
+
lastExecution = null;
|
|
10
|
+
runOnce = false;
|
|
11
|
+
context;
|
|
12
|
+
onComplete;
|
|
13
|
+
waitForCompletion = false;
|
|
14
|
+
errorHandler;
|
|
15
|
+
name;
|
|
16
|
+
threshold = 250;
|
|
17
|
+
_isActive = false;
|
|
18
|
+
_isCallbackRunning = false;
|
|
19
|
+
_timeout;
|
|
20
|
+
_callbacks = [];
|
|
16
21
|
get isActive() {
|
|
17
22
|
return this._isActive;
|
|
18
23
|
}
|
|
@@ -20,27 +25,19 @@ class CronJob {
|
|
|
20
25
|
return this._isCallbackRunning;
|
|
21
26
|
}
|
|
22
27
|
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler, name, threshold, usedFrom) {
|
|
23
|
-
this.unrefTimeout = false;
|
|
24
|
-
this.lastExecution = null;
|
|
25
|
-
this.runOnce = false;
|
|
26
|
-
this.waitForCompletion = false;
|
|
27
|
-
this.threshold = 250;
|
|
28
|
-
this._isActive = false;
|
|
29
|
-
this._isCallbackRunning = false;
|
|
30
|
-
this._callbacks = [];
|
|
31
28
|
if (!usedFrom) {
|
|
32
29
|
console.warn(`[Cron] Warning: The parameterized constructor is deprecated and will be removed in the next major version of Cron (v6).
|
|
33
30
|
\n Consider updating the instantiation of your CronJob object to use the static 'from' method.
|
|
34
31
|
\n See https://github.com/kelektiv/node-cron#deprecated-the-parameterized-constructor`);
|
|
35
32
|
}
|
|
36
|
-
this.context = (context
|
|
33
|
+
this.context = (context ?? this);
|
|
37
34
|
this.waitForCompletion = Boolean(waitForCompletion);
|
|
38
35
|
this.errorHandler = errorHandler;
|
|
39
36
|
(0, errors_1.assertExclusiveTimeZoneAndUtcOffset)(timeZone, utcOffset);
|
|
40
37
|
this.cronTime =
|
|
41
38
|
timeZone != null
|
|
42
39
|
? new time_1.CronTime(cronTime, timeZone, null)
|
|
43
|
-
: new time_1.CronTime(cronTime, null, utcOffset
|
|
40
|
+
: new time_1.CronTime(cronTime, null, utcOffset ?? null);
|
|
44
41
|
if (unrefTimeout != null) {
|
|
45
42
|
this.unrefTimeout = unrefTimeout;
|
|
46
43
|
}
|
|
@@ -99,44 +96,42 @@ class CronJob {
|
|
|
99
96
|
nextDate() {
|
|
100
97
|
return this.cronTime.sendAt();
|
|
101
98
|
}
|
|
102
|
-
fireOnTick() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
123
|
-
}
|
|
99
|
+
async fireOnTick() {
|
|
100
|
+
if (this.waitForCompletion && this._isCallbackRunning)
|
|
101
|
+
return;
|
|
102
|
+
this._isCallbackRunning = true;
|
|
103
|
+
try {
|
|
104
|
+
for (const callback of this._callbacks) {
|
|
105
|
+
const result = callback.call(this.context, this.onComplete);
|
|
106
|
+
if (result &&
|
|
107
|
+
typeof result === 'object' &&
|
|
108
|
+
typeof result.then === 'function') {
|
|
109
|
+
if (this.waitForCompletion) {
|
|
110
|
+
await result;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
result.catch(error => {
|
|
114
|
+
if (this.errorHandler != null)
|
|
115
|
+
this.errorHandler(error);
|
|
116
|
+
else
|
|
117
|
+
console.error('[Cron] error in callback', error);
|
|
118
|
+
});
|
|
124
119
|
}
|
|
125
120
|
}
|
|
126
121
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (this.errorHandler != null)
|
|
125
|
+
this.errorHandler(error);
|
|
126
|
+
else
|
|
127
|
+
console.error('[Cron] error in callback', error);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
this._isCallbackRunning = false;
|
|
131
|
+
}
|
|
137
132
|
}
|
|
138
133
|
nextDates(i) {
|
|
139
|
-
return this.cronTime.sendAt(i
|
|
134
|
+
return this.cronTime.sendAt(i ?? 0);
|
|
140
135
|
}
|
|
141
136
|
start() {
|
|
142
137
|
if (this._isActive)
|
|
@@ -206,24 +201,20 @@ class CronJob {
|
|
|
206
201
|
lastDate() {
|
|
207
202
|
return this.lastExecution;
|
|
208
203
|
}
|
|
209
|
-
_executeOnComplete() {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
});
|
|
204
|
+
async _executeOnComplete() {
|
|
205
|
+
if (typeof this.onComplete !== 'function')
|
|
206
|
+
return;
|
|
207
|
+
try {
|
|
208
|
+
await this.onComplete.call(this.context);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
console.error('[Cron] error in onComplete callback:', error);
|
|
212
|
+
}
|
|
220
213
|
}
|
|
221
|
-
_waitForJobCompletion() {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
});
|
|
214
|
+
async _waitForJobCompletion() {
|
|
215
|
+
while (this._isCallbackRunning) {
|
|
216
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
217
|
+
}
|
|
227
218
|
}
|
|
228
219
|
stop() {
|
|
229
220
|
if (this._timeout)
|
|
@@ -233,10 +224,10 @@ class CronJob {
|
|
|
233
224
|
void this._executeOnComplete();
|
|
234
225
|
return;
|
|
235
226
|
}
|
|
236
|
-
return Promise.resolve().then(() =>
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})
|
|
227
|
+
return Promise.resolve().then(async () => {
|
|
228
|
+
await this._waitForJobCompletion();
|
|
229
|
+
await this._executeOnComplete();
|
|
230
|
+
});
|
|
240
231
|
}
|
|
241
232
|
}
|
|
242
233
|
exports.CronJob = CronJob;
|
package/dist/time.js
CHANGED
|
@@ -5,14 +5,17 @@ const luxon_1 = require("luxon");
|
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
class CronTime {
|
|
8
|
+
source;
|
|
9
|
+
timeZone;
|
|
10
|
+
utcOffset;
|
|
11
|
+
realDate = false;
|
|
12
|
+
second = {};
|
|
13
|
+
minute = {};
|
|
14
|
+
hour = {};
|
|
15
|
+
dayOfMonth = {};
|
|
16
|
+
month = {};
|
|
17
|
+
dayOfWeek = {};
|
|
8
18
|
constructor(source, timeZone, utcOffset) {
|
|
9
|
-
this.realDate = false;
|
|
10
|
-
this.second = {};
|
|
11
|
-
this.minute = {};
|
|
12
|
-
this.hour = {};
|
|
13
|
-
this.dayOfMonth = {};
|
|
14
|
-
this.month = {};
|
|
15
|
-
this.dayOfWeek = {};
|
|
16
19
|
(0, errors_1.assertExclusiveTimeZoneAndUtcOffset)(timeZone, utcOffset);
|
|
17
20
|
if (timeZone) {
|
|
18
21
|
const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
|
|
@@ -136,7 +139,6 @@ class CronTime {
|
|
|
136
139
|
});
|
|
137
140
|
}
|
|
138
141
|
getNextDateFrom(start, timeZone) {
|
|
139
|
-
var _a, _b, _c, _d;
|
|
140
142
|
if (start instanceof Date) {
|
|
141
143
|
start = luxon_1.DateTime.fromJSDate(start);
|
|
142
144
|
}
|
|
@@ -144,7 +146,7 @@ class CronTime {
|
|
|
144
146
|
start = start.setZone(timeZone);
|
|
145
147
|
}
|
|
146
148
|
else {
|
|
147
|
-
timeZone =
|
|
149
|
+
timeZone = start.zone.zoneName ?? start.zone.fixed;
|
|
148
150
|
}
|
|
149
151
|
let date = luxon_1.DateTime.fromFormat(`${start.year}-${start.month}-${start.day} ${start.hour}:${start.minute}:${start.second}`, 'yyyy-M-d H:m:s', {
|
|
150
152
|
zone: 'UTC'
|
|
@@ -163,7 +165,7 @@ class CronTime {
|
|
|
163
165
|
if (date > maxMatch) {
|
|
164
166
|
throw new errors_1.CronError(`Something went wrong. No execution date was found in the next 8 years.
|
|
165
167
|
Please provide the following string if you would like to help debug:
|
|
166
|
-
Time Zone: ${
|
|
168
|
+
Time Zone: ${timeZone?.toString() ?? '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
|
|
167
169
|
}
|
|
168
170
|
if (!(date.month in this.month) &&
|
|
169
171
|
Object.keys(this.month).length !== 12) {
|
|
@@ -219,7 +221,7 @@ class CronTime {
|
|
|
219
221
|
(hourTestDate.offset > date.offset ||
|
|
220
222
|
twoHourTestDate.offset > hourTestDate.offset) &&
|
|
221
223
|
hourTestDate > start) {
|
|
222
|
-
date =
|
|
224
|
+
date = this._firstMatchBetween(hourTestDate, date) ?? date;
|
|
223
225
|
}
|
|
224
226
|
const halfHourTestDate = date.minus({ minute: 30 });
|
|
225
227
|
if ((halfHourTestDate.minute === date.minute ||
|
|
@@ -227,7 +229,7 @@ class CronTime {
|
|
|
227
229
|
(halfHourTestDate.offset > date.offset ||
|
|
228
230
|
hourTestDate.offset > halfHourTestDate.offset) &&
|
|
229
231
|
halfHourTestDate > start) {
|
|
230
|
-
date =
|
|
232
|
+
date = this._firstMatchBetween(halfHourTestDate, date) ?? date;
|
|
231
233
|
}
|
|
232
234
|
return date;
|
|
233
235
|
}
|
|
@@ -253,7 +255,6 @@ class CronTime {
|
|
|
253
255
|
return true;
|
|
254
256
|
}
|
|
255
257
|
_parse(source) {
|
|
256
|
-
var _a;
|
|
257
258
|
source = source.toLowerCase();
|
|
258
259
|
if (Object.keys(constants_1.PRESETS).includes(source)) {
|
|
259
260
|
source = constants_1.PRESETS[source];
|
|
@@ -274,7 +275,7 @@ class CronTime {
|
|
|
274
275
|
const unitsLen = units.length;
|
|
275
276
|
for (const unit of constants_1.TIME_UNITS) {
|
|
276
277
|
const i = constants_1.TIME_UNITS.indexOf(unit);
|
|
277
|
-
const cur =
|
|
278
|
+
const cur = units[i - (constants_1.TIME_UNITS_LEN - unitsLen)] ?? constants_1.PARSE_DEFAULTS[unit];
|
|
278
279
|
this._parseField(cur, unit);
|
|
279
280
|
}
|
|
280
281
|
}
|
|
@@ -295,12 +296,12 @@ class CronTime {
|
|
|
295
296
|
const allRanges = value.split(',');
|
|
296
297
|
for (const range of allRanges) {
|
|
297
298
|
const match = [...range.matchAll(constants_1.RE_RANGE)][0];
|
|
298
|
-
if (
|
|
299
|
+
if (match?.[1] !== undefined) {
|
|
299
300
|
const [, mLower, mUpper, mStep] = match;
|
|
300
301
|
let lower = parseInt(mLower, 10);
|
|
301
302
|
let upper = mUpper !== undefined ? parseInt(mUpper, 10) : undefined;
|
|
302
303
|
const wasStepDefined = mStep !== undefined;
|
|
303
|
-
const step = parseInt(mStep
|
|
304
|
+
const step = parseInt(mStep ?? '1', 10);
|
|
304
305
|
if (step === 0) {
|
|
305
306
|
throw new errors_1.CronError(`Field (${unit}) has a step of zero`);
|
|
306
307
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.4",
|
|
5
5
|
"author": "Brandon der Blätter <https://intcreator.com/> (https://github.com/intcreator)",
|
|
6
6
|
"funding": {
|
|
7
7
|
"type": "ko-fi",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"prepare": "husky"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@types/luxon": "~3.7.
|
|
32
|
-
"luxon": "~3.7.
|
|
31
|
+
"@types/luxon": "~3.7.6",
|
|
32
|
+
"luxon": "~3.7.2"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@commitlint/cli": "20.5.3",
|