cron 4.4.0 → 5.0.0-beta.2
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 +1478 -0
- package/README.md +85 -59
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +7 -1
- package/dist/job.d.ts +3 -3
- package/dist/job.js +20 -37
- package/dist/time.d.ts +1 -2
- package/dist/time.js +1 -3
- package/dist/types/cron.types.d.ts +3 -8
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<img src="logo.svg" alt="cron for Node.js logo" height="150">
|
|
3
3
|
<br />
|
|
4
|
-
<b>cron</b> is a robust tool for running jobs (functions
|
|
4
|
+
<b>cron</b> is a robust tool for running jobs (functions) on schedules defined using the cron syntax.
|
|
5
5
|
<br />
|
|
6
6
|
Perfect for tasks like data backups, notifications, and many more!
|
|
7
7
|
</p>
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
## 🌟 Features
|
|
21
21
|
|
|
22
22
|
- execute a function whenever your scheduled job triggers
|
|
23
|
-
- execute a job external to the javascript process (like a system command) using `child_process`
|
|
24
23
|
- use a Date or Luxon DateTime object instead of cron syntax as the trigger for your callback
|
|
25
24
|
- use an additional slot for seconds (leaving it off will default to 0 and match the Unix behavior)
|
|
26
25
|
|
|
@@ -54,6 +53,44 @@ npm install cron
|
|
|
54
53
|
|
|
55
54
|
## ⬆ Migrating
|
|
56
55
|
|
|
56
|
+
v5 dropped Node v18, v20, and v23; deprecated the parameterized constructor, and removed `child_process`
|
|
57
|
+
|
|
58
|
+
<details>
|
|
59
|
+
<summary>Migrating from v4 to v5</summary>
|
|
60
|
+
|
|
61
|
+
### Dropped Node versions
|
|
62
|
+
|
|
63
|
+
Node v18, v20, and v23 are no longer supported. Upgrade your Node installation to v22, v24, or v26.
|
|
64
|
+
|
|
65
|
+
### Deprecated the parameterized constructor
|
|
66
|
+
|
|
67
|
+
Previously this was the recommended way to create new `CronJob` objects:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const job = new CronJob('* * * * * *', function () {
|
|
71
|
+
console.log('You will see this message every second');
|
|
72
|
+
});
|
|
73
|
+
```
|
|
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.
|
|
76
|
+
|
|
77
|
+
Instead, create `CronJob` objects like this:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
const job = CronJob.from({
|
|
81
|
+
cronTime: '* * * * * *',
|
|
82
|
+
onTick: function () {
|
|
83
|
+
console.log('You will see this message every second');
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Removed `child_process` dependency and native system command support
|
|
89
|
+
|
|
90
|
+
In anticipation of one day offering browser support, the ability to execute system commands natively with `child_process` has been removed. There are other ways to execute system commands in Node, so this functionality is still possible by other means if you need it, it may just require some refactoring.
|
|
91
|
+
|
|
92
|
+
</details>
|
|
93
|
+
|
|
57
94
|
v4 dropped Node v16 and renamed the `job.running` property:
|
|
58
95
|
|
|
59
96
|
<details>
|
|
@@ -96,36 +133,22 @@ v3 introduced TypeScript and tighter Unix cron pattern alignment:
|
|
|
96
133
|
|
|
97
134
|
## 🛠 Basic Usage
|
|
98
135
|
|
|
99
|
-
```
|
|
136
|
+
```js
|
|
100
137
|
import { CronJob } from 'cron';
|
|
101
138
|
|
|
102
|
-
const job = new CronJob(
|
|
103
|
-
'* * * * * *', // cronTime
|
|
104
|
-
function () {
|
|
105
|
-
console.log('You will see this message every second');
|
|
106
|
-
}, // onTick
|
|
107
|
-
null, // onComplete
|
|
108
|
-
true, // start
|
|
109
|
-
'America/Los_Angeles' // timeZone
|
|
110
|
-
);
|
|
111
|
-
// job.start() is optional here because of the fourth parameter set to true.
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
```javascript
|
|
115
|
-
// equivalent job using the "from" static method, providing parameters as an object
|
|
116
139
|
const job = CronJob.from({
|
|
117
140
|
cronTime: '* * * * * *',
|
|
118
141
|
onTick: function () {
|
|
119
142
|
console.log('You will see this message every second');
|
|
120
143
|
},
|
|
121
|
-
start: true,
|
|
122
|
-
timeZone: 'America/Los_Angeles'
|
|
144
|
+
start: true, // optional
|
|
145
|
+
timeZone: 'America/Los_Angeles' // optional
|
|
123
146
|
});
|
|
124
147
|
```
|
|
125
148
|
|
|
126
|
-
> **Note:** In the
|
|
149
|
+
> **Note:** In the example above, the `start` property set to `true` starts the job automatically. If not provided or set to `false`, you must explicitly start the job using `job.start()`.
|
|
127
150
|
|
|
128
|
-
For more advanced examples, check the [examples directory](https://github.com/kelektiv/node-cron/tree/main/examples).
|
|
151
|
+
See the [API below](#api) for all properties. For more advanced examples, check the [examples directory](https://github.com/kelektiv/node-cron/tree/main/examples).
|
|
129
152
|
|
|
130
153
|
## ⏰ Cron Patterns
|
|
131
154
|
|
|
@@ -141,7 +164,7 @@ Detailed patterns and explanations are available at [crontab.org](http://crontab
|
|
|
141
164
|
|
|
142
165
|
### Supported Ranges
|
|
143
166
|
|
|
144
|
-
Here's a quick reference to the UNIX Cron format this library uses, plus an
|
|
167
|
+
Here's a quick reference to the UNIX Cron format this library uses, plus an additional `second` field:
|
|
145
168
|
|
|
146
169
|
```
|
|
147
170
|
field allowed values
|
|
@@ -159,43 +182,11 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
159
182
|
|
|
160
183
|
## 📖 API
|
|
161
184
|
|
|
162
|
-
### Standalone Functions
|
|
163
|
-
|
|
164
|
-
- `sendAt`: Indicates when a `CronTime` will execute (returns a Luxon `DateTime` object).
|
|
165
|
-
|
|
166
|
-
```javascript
|
|
167
|
-
import * as cron from 'cron';
|
|
168
|
-
|
|
169
|
-
const dt = cron.sendAt('0 0 * * *');
|
|
170
|
-
console.log(`The job would run at: ${dt.toISO()}`);
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
- `timeout`: Indicates the number of milliseconds in the future at which a `CronTime` will execute (returns a number).
|
|
174
|
-
|
|
175
|
-
```javascript
|
|
176
|
-
import * as cron from 'cron';
|
|
177
|
-
|
|
178
|
-
const timeout = cron.timeout('0 0 * * *');
|
|
179
|
-
console.log(`The job would run in ${timeout}ms`);
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
- `validateCronExpression`: Validates if a given cron expression is valid (returns an object with `valid` and `error` properties).
|
|
183
|
-
|
|
184
|
-
```javascript
|
|
185
|
-
import * as cron from 'cron';
|
|
186
|
-
|
|
187
|
-
const validation = cron.validateCronExpression('0 0 * * *');
|
|
188
|
-
console.log(`Is the cron expression valid? ${validation.valid}`);
|
|
189
|
-
if (!validation.valid) {
|
|
190
|
-
console.error(`Validation error: ${validation.error}`);
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
185
|
### CronJob Class
|
|
195
186
|
|
|
196
187
|
#### Constructor
|
|
197
188
|
|
|
198
|
-
`
|
|
189
|
+
`CronJob.from({ ... })`:
|
|
199
190
|
|
|
200
191
|
- `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
192
|
|
|
@@ -250,10 +241,13 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
250
241
|
- `isCallbackRunning`: [READ-ONLY] Indicates if a callback is currently executing.
|
|
251
242
|
|
|
252
243
|
```javascript
|
|
253
|
-
const job = new CronJob(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
244
|
+
const job = new CronJob.from({
|
|
245
|
+
cronTime: '* * * * * *',
|
|
246
|
+
onTick: async () => {
|
|
247
|
+
console.log(job.isCallbackRunning); // true during callback execution
|
|
248
|
+
await someAsyncTask();
|
|
249
|
+
console.log(job.isCallbackRunning); // still true until callback completes
|
|
250
|
+
}
|
|
257
251
|
});
|
|
258
252
|
|
|
259
253
|
console.log(job.isCallbackRunning); // false
|
|
@@ -274,6 +268,38 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
|
|
|
274
268
|
|
|
275
269
|
- `utcOffset`: [OPTIONAL] - Analogous to `utcOffset` from `CronJob` parameters.
|
|
276
270
|
|
|
271
|
+
### Standalone Functions
|
|
272
|
+
|
|
273
|
+
- `sendAt`: Indicates when a `CronTime` will execute (returns a Luxon `DateTime` object).
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
import * as cron from 'cron';
|
|
277
|
+
|
|
278
|
+
const dt = cron.sendAt('0 0 * * *');
|
|
279
|
+
console.log(`The job would run at: ${dt.toISO()}`);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- `timeout`: Indicates the number of milliseconds in the future at which a `CronTime` will execute (returns a number).
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
import * as cron from 'cron';
|
|
286
|
+
|
|
287
|
+
const timeout = cron.timeout('0 0 * * *');
|
|
288
|
+
console.log(`The job would run in ${timeout}ms`);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
- `validateCronExpression`: Validates if a given cron expression is valid (returns an object with `valid` and `error` properties).
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
import * as cron from 'cron';
|
|
295
|
+
|
|
296
|
+
const validation = cron.validateCronExpression('0 0 * * *');
|
|
297
|
+
console.log(`Is the cron expression valid? ${validation.valid}`);
|
|
298
|
+
if (!validation.valid) {
|
|
299
|
+
console.error(`Validation error: ${validation.error}`);
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
277
303
|
## 💢 Gotchas
|
|
278
304
|
|
|
279
305
|
- 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.
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare class CronError extends Error {
|
|
|
3
3
|
export declare class ExclusiveParametersError extends CronError {
|
|
4
4
|
constructor(param1: string, param2: string);
|
|
5
5
|
}
|
|
6
|
+
export declare const assertExclusiveTimeZoneAndUtcOffset: (timeZone?: string | null, utcOffset?: number | null) => void;
|
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExclusiveParametersError = exports.CronError = void 0;
|
|
3
|
+
exports.assertExclusiveTimeZoneAndUtcOffset = exports.ExclusiveParametersError = exports.CronError = void 0;
|
|
4
4
|
class CronError extends Error {
|
|
5
5
|
}
|
|
6
6
|
exports.CronError = CronError;
|
|
@@ -10,3 +10,9 @@ class ExclusiveParametersError extends CronError {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.ExclusiveParametersError = ExclusiveParametersError;
|
|
13
|
+
const assertExclusiveTimeZoneAndUtcOffset = (timeZone, utcOffset) => {
|
|
14
|
+
if (timeZone != null && utcOffset != null) {
|
|
15
|
+
throw new ExclusiveParametersError('timeZone', 'utcOffset');
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.assertExclusiveTimeZoneAndUtcOffset = assertExclusiveTimeZoneAndUtcOffset;
|
package/dist/job.d.ts
CHANGED
|
@@ -17,10 +17,10 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
17
17
|
private _callbacks;
|
|
18
18
|
get isActive(): boolean;
|
|
19
19
|
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'], name?: CronJobParams<OC, C>['name'], threshold?: CronJobParams<OC, C>['threshold']);
|
|
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'], name?: CronJobParams<OC, C>['name'], threshold?: CronJobParams<OC, C>['threshold']);
|
|
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'], name?: CronJobParams<OC, C>['name'], threshold?: CronJobParams<OC, C>['threshold'], usedFrom?: CronJobParams<OC, C>['usedFrom']);
|
|
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'], name?: CronJobParams<OC, C>['name'], threshold?: CronJobParams<OC, C>['threshold'], usedFrom?: CronJobParams<OC, C>['usedFrom']);
|
|
22
22
|
static from<OC extends CronOnCompleteCommand | null = null, C = null>(params: CronJobParams<OC, C>): CronJob<OC, C>;
|
|
23
|
-
private
|
|
23
|
+
private isCronOnCompleteCallback;
|
|
24
24
|
addCallback(callback: CronCallback<C, WithOnComplete<OC>>): void;
|
|
25
25
|
setTime(time: CronTime): void;
|
|
26
26
|
nextDate(): import("luxon").DateTime<boolean>;
|
package/dist/job.js
CHANGED
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CronJob = void 0;
|
|
13
|
-
const child_process_1 = require("child_process");
|
|
14
13
|
const errors_1 = require("./errors");
|
|
15
14
|
const time_1 = require("./time");
|
|
16
15
|
class CronJob {
|
|
@@ -20,7 +19,7 @@ class CronJob {
|
|
|
20
19
|
get isCallbackRunning() {
|
|
21
20
|
return this._isCallbackRunning;
|
|
22
21
|
}
|
|
23
|
-
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler, name, threshold) {
|
|
22
|
+
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler, name, threshold, usedFrom) {
|
|
24
23
|
this.unrefTimeout = false;
|
|
25
24
|
this.lastExecution = null;
|
|
26
25
|
this.runOnce = false;
|
|
@@ -29,26 +28,24 @@ class CronJob {
|
|
|
29
28
|
this._isActive = false;
|
|
30
29
|
this._isCallbackRunning = false;
|
|
31
30
|
this._callbacks = [];
|
|
31
|
+
if (!usedFrom) {
|
|
32
|
+
console.warn(`[Cron] Warning: The parameterized constructor is deprecated and will be removed in the next major version of Cron (v6).
|
|
33
|
+
\n Consider updating the instantiation of your CronJob object to use the static 'from' method.
|
|
34
|
+
\n See https://github.com/kelektiv/node-cron#deprecated-the-parameterized-constructor`);
|
|
35
|
+
}
|
|
32
36
|
this.context = (context !== null && context !== void 0 ? context : this);
|
|
33
37
|
this.waitForCompletion = Boolean(waitForCompletion);
|
|
34
38
|
this.errorHandler = errorHandler;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
else if (utcOffset != null) {
|
|
42
|
-
this.cronTime = new time_1.CronTime(cronTime, null, utcOffset);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
|
|
46
|
-
}
|
|
39
|
+
(0, errors_1.assertExclusiveTimeZoneAndUtcOffset)(timeZone, utcOffset);
|
|
40
|
+
this.cronTime =
|
|
41
|
+
timeZone != null
|
|
42
|
+
? new time_1.CronTime(cronTime, timeZone, null)
|
|
43
|
+
: new time_1.CronTime(cronTime, null, utcOffset !== null && utcOffset !== void 0 ? utcOffset : null);
|
|
47
44
|
if (unrefTimeout != null) {
|
|
48
45
|
this.unrefTimeout = unrefTimeout;
|
|
49
46
|
}
|
|
50
|
-
if (onComplete
|
|
51
|
-
this.onComplete =
|
|
47
|
+
if (this.isCronOnCompleteCallback(onComplete)) {
|
|
48
|
+
this.onComplete = onComplete;
|
|
52
49
|
}
|
|
53
50
|
if (threshold != null) {
|
|
54
51
|
this.threshold = Math.abs(threshold);
|
|
@@ -59,7 +56,7 @@ class CronJob {
|
|
|
59
56
|
if (this.cronTime.realDate) {
|
|
60
57
|
this.runOnce = true;
|
|
61
58
|
}
|
|
62
|
-
this.addCallback(
|
|
59
|
+
this.addCallback(onTick);
|
|
63
60
|
if (runOnInit) {
|
|
64
61
|
this.lastExecution = new Date();
|
|
65
62
|
void this.fireOnTick();
|
|
@@ -68,33 +65,19 @@ class CronJob {
|
|
|
68
65
|
this.start();
|
|
69
66
|
}
|
|
70
67
|
static from(params) {
|
|
71
|
-
|
|
72
|
-
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
73
|
-
}
|
|
68
|
+
(0, errors_1.assertExclusiveTimeZoneAndUtcOffset)(params.timeZone, params.utcOffset);
|
|
74
69
|
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, params.name, params.threshold);
|
|
70
|
+
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, params.name, params.threshold, true);
|
|
76
71
|
}
|
|
77
72
|
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, params.name, params.threshold);
|
|
73
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler, params.name, params.threshold, true);
|
|
79
74
|
}
|
|
80
75
|
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, params.name, params.threshold);
|
|
76
|
+
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, params.name, params.threshold, true);
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
switch (typeof cmd) {
|
|
87
|
-
case 'function': {
|
|
88
|
-
return cmd;
|
|
89
|
-
}
|
|
90
|
-
case 'string': {
|
|
91
|
-
const [command, ...args] = cmd.split(' ');
|
|
92
|
-
return child_process_1.spawn.bind(undefined, command !== null && command !== void 0 ? command : cmd, args, {});
|
|
93
|
-
}
|
|
94
|
-
case 'object': {
|
|
95
|
-
return child_process_1.spawn.bind(undefined, cmd.command, (_a = cmd.args) !== null && _a !== void 0 ? _a : [], (_b = cmd.options) !== null && _b !== void 0 ? _b : {});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
79
|
+
isCronOnCompleteCallback(fn) {
|
|
80
|
+
return typeof fn === 'function';
|
|
98
81
|
}
|
|
99
82
|
addCallback(callback) {
|
|
100
83
|
if (typeof callback === 'function') {
|
package/dist/time.d.ts
CHANGED
|
@@ -19,8 +19,7 @@ export declare class CronTime {
|
|
|
19
19
|
private dayOfMonth;
|
|
20
20
|
private month;
|
|
21
21
|
private dayOfWeek;
|
|
22
|
-
constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?:
|
|
23
|
-
constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
|
|
22
|
+
constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: CronJobParams['utcOffset']);
|
|
24
23
|
static validateCronExpression(cronExpression: string): {
|
|
25
24
|
valid: boolean;
|
|
26
25
|
error?: CronError;
|
package/dist/time.js
CHANGED
|
@@ -13,9 +13,7 @@ class CronTime {
|
|
|
13
13
|
this.dayOfMonth = {};
|
|
14
14
|
this.month = {};
|
|
15
15
|
this.dayOfWeek = {};
|
|
16
|
-
|
|
17
|
-
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
18
|
-
}
|
|
16
|
+
(0, errors_1.assertExclusiveTimeZoneAndUtcOffset)(timeZone, utcOffset);
|
|
19
17
|
if (timeZone) {
|
|
20
18
|
const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
|
|
21
19
|
if (!dt.isValid) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SpawnOptions } from 'child_process';
|
|
2
1
|
import { DateTime } from 'luxon';
|
|
3
2
|
import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants';
|
|
4
3
|
import { CronJob } from '../job';
|
|
@@ -14,6 +13,7 @@ interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C =
|
|
|
14
13
|
waitForCompletion?: boolean | null;
|
|
15
14
|
errorHandler?: ((error: unknown) => void) | null;
|
|
16
15
|
threshold?: number | null;
|
|
16
|
+
usedFrom?: boolean | null;
|
|
17
17
|
name?: string | null;
|
|
18
18
|
}
|
|
19
19
|
export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> & ({
|
|
@@ -26,13 +26,8 @@ export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = nu
|
|
|
26
26
|
export type CronContext<C> = C extends null ? CronJob : NonNullable<C>;
|
|
27
27
|
export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (this: CronContext<C>, onComplete: WithOnCompleteBool extends true ? CronOnCompleteCallback : never) => void | Promise<void>;
|
|
28
28
|
export type CronOnCompleteCallback = () => void | Promise<void>;
|
|
29
|
-
export type
|
|
30
|
-
|
|
31
|
-
args?: readonly string[] | null;
|
|
32
|
-
options?: SpawnOptions | null;
|
|
33
|
-
};
|
|
34
|
-
export type CronCommand<C, WithOnCompleteBool extends boolean = false> = CronCallback<C, WithOnCompleteBool> | CronSystemCommand;
|
|
35
|
-
export type CronOnCompleteCommand = CronOnCompleteCallback | CronSystemCommand;
|
|
29
|
+
export type CronCommand<C, WithOnCompleteBool extends boolean = false> = CronCallback<C, WithOnCompleteBool>;
|
|
30
|
+
export type CronOnCompleteCommand = CronOnCompleteCallback;
|
|
36
31
|
export type WithOnComplete<OC> = OC extends null ? false : true;
|
|
37
32
|
export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP];
|
|
38
33
|
export type TimeUnitField<T extends TimeUnit> = Partial<Record<Ranges[T], boolean>>;
|
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": "5.0.0-beta.2",
|
|
5
5
|
"author": "Brandon der Blätter <https://intcreator.com/> (https://github.com/intcreator)",
|
|
6
6
|
"funding": {
|
|
7
7
|
"type": "ko-fi",
|
|
@@ -32,33 +32,33 @@
|
|
|
32
32
|
"luxon": "~3.7.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@commitlint/cli": "20.
|
|
36
|
-
"@eslint/js": "9.39.
|
|
37
|
-
"@fast-check/jest": "2.
|
|
35
|
+
"@commitlint/cli": "20.5.3",
|
|
36
|
+
"@eslint/js": "9.39.4",
|
|
37
|
+
"@fast-check/jest": "2.2.0",
|
|
38
38
|
"@insurgent/commitlint-config": "20.0.0",
|
|
39
39
|
"@insurgent/conventional-changelog-preset": "10.0.0",
|
|
40
40
|
"@semantic-release/changelog": "6.0.3",
|
|
41
41
|
"@semantic-release/commit-analyzer": "13.0.1",
|
|
42
42
|
"@semantic-release/git": "10.0.1",
|
|
43
|
-
"@semantic-release/github": "12.0.
|
|
44
|
-
"@semantic-release/npm": "13.1.
|
|
45
|
-
"@semantic-release/release-notes-generator": "14.1.
|
|
46
|
-
"@swc/core": "1.
|
|
43
|
+
"@semantic-release/github": "12.0.9",
|
|
44
|
+
"@semantic-release/npm": "13.1.5",
|
|
45
|
+
"@semantic-release/release-notes-generator": "14.1.1",
|
|
46
|
+
"@swc/core": "1.16.1",
|
|
47
47
|
"@swc/jest": "0.2.39",
|
|
48
48
|
"@types/jest": "30.0.0",
|
|
49
|
-
"@types/node": "
|
|
50
|
-
"@types/sinon": "
|
|
49
|
+
"@types/node": "24.13.3",
|
|
50
|
+
"@types/sinon": "22.0.0",
|
|
51
51
|
"cross-env": "7.0.3",
|
|
52
52
|
"eslint": "8.57.1",
|
|
53
53
|
"eslint-config-prettier": "9.1.2",
|
|
54
54
|
"eslint-plugin-jest": "27.9.0",
|
|
55
|
-
"eslint-plugin-prettier": "5.5.
|
|
55
|
+
"eslint-plugin-prettier": "5.5.6",
|
|
56
56
|
"husky": "9.1.7",
|
|
57
|
-
"jest": "30.2
|
|
57
|
+
"jest": "30.4.2",
|
|
58
58
|
"lint-staged": "15.5.2",
|
|
59
|
-
"prettier": "3.
|
|
60
|
-
"semantic-release": "25.0.
|
|
61
|
-
"sinon": "
|
|
59
|
+
"prettier": "3.8.4",
|
|
60
|
+
"semantic-release": "25.0.9",
|
|
61
|
+
"sinon": "22.1.0",
|
|
62
62
|
"typescript": "5.9.3",
|
|
63
63
|
"typescript-eslint": "7.18.0"
|
|
64
64
|
},
|