cron 3.0.0-beta.8 → 3.0.0-beta.9
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 +25 -0
- package/README.md +5 -9
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +10 -0
- package/dist/job.d.ts +2 -1
- package/dist/job.js +25 -2
- package/dist/time.d.ts +6 -4
- package/dist/time.js +22 -28
- package/dist/types/cron.types.d.ts +9 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
## [3.0.0-beta.9](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2023-09-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### ⚠ Breaking changes
|
|
5
|
+
|
|
6
|
+
* `utcOffset` parameter no longer accepts a string
|
|
7
|
+
* `utcOffset` values between -60 and 60 are no longer
|
|
8
|
+
treated as hours
|
|
9
|
+
* providing both `timeZone` and `utcOffset` parameters
|
|
10
|
+
now throws an error
|
|
11
|
+
|
|
12
|
+
### ✨ Features
|
|
13
|
+
|
|
14
|
+
* rework utcOffset parameter ([#699](https://github.com/kelektiv/node-cron/issues/699)) ([72d3d36](https://github.com/kelektiv/node-cron/commit/72d3d36c47b037cf4ce489c6b57b0a8b4e000a04))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### ♻️ Chores
|
|
18
|
+
|
|
19
|
+
* improve GitHub community standards ([#698](https://github.com/kelektiv/node-cron/issues/698)) ([6bdef77](https://github.com/kelektiv/node-cron/commit/6bdef779b813ee84c03b7c708176410aa24a8cfe))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### 💎 Styles
|
|
23
|
+
|
|
24
|
+
* fix linting issues ([b48c1b2](https://github.com/kelektiv/node-cron/commit/b48c1b299a25bfd3aea418652235e4e6ec92f8cf))
|
|
25
|
+
|
|
1
26
|
## [3.0.0-beta.8](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2023-09-26)
|
|
2
27
|
|
|
3
28
|
|
package/README.md
CHANGED
|
@@ -120,10 +120,10 @@ Parameter Based
|
|
|
120
120
|
- `onTick` - [REQUIRED] - The function to fire at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument. `onTick` may call `onComplete` when it has finished its work.
|
|
121
121
|
- `onComplete` - [OPTIONAL] - A function that will fire when the job is stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
|
|
122
122
|
- `start` - [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call `job.start()` in order to start the job (assuming `job` is the variable you set the cronjob to). This does not immediately fire your `onTick` function, it just gives you more control over the behavior of your jobs.
|
|
123
|
-
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check the various time zones format accepted in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Note: This parameter supports minutes offsets, e.g. `UTC+5:30`. **
|
|
123
|
+
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check the various time zones format accepted in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Note: This parameter supports minutes offsets, e.g. `UTC+5:30`. **Note**: Cannot be used together with `utcOffset`.
|
|
124
124
|
- `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
|
|
125
125
|
- `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick` function as soon as the requisite initialization has happened. This option is set to `false` by default for backwards compatibility.
|
|
126
|
-
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours). **
|
|
126
|
+
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours). **Note**: Cannot be used together with `timeZone`.
|
|
127
127
|
- `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.
|
|
128
128
|
- `from` (static) - Create a new CronJob object providing arguments as an object. See argument names and descriptions above.
|
|
129
129
|
- `start` - Runs your job.
|
|
@@ -146,17 +146,13 @@ Join the [Discord server](https://discord.gg/yyKns29zch)! Here you can discuss i
|
|
|
146
146
|
|
|
147
147
|
## Contributing
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
This project is looking for help! If you're interested in helping with the project please reach out to me (ncb000gt) on [Twitter](https://twitter.com/ncb000gt). We'd love for it to continue on, but it needs a lot of attention. You can also join the [Discord server](https://discord.gg/yyKns29zch) to learn more about what needs to be done.
|
|
149
|
+
This project is looking for help! If you're interested in helping with the project, please take a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md).
|
|
152
150
|
|
|
153
151
|
### Submitting Bugs/Issues
|
|
154
152
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Because we can't magically know what you are doing to expose an issue, it is best if you provide a snippet of code. This snippet need not include your secret sauce, but it must replicate the issue you are describing. The issues that get closed without resolution tend to be the ones without code examples. Thanks.
|
|
153
|
+
Please have a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md), it contains all the information you need to know before submitting an issue.
|
|
158
154
|
|
|
159
|
-
|
|
155
|
+
## Acknowledgements
|
|
160
156
|
|
|
161
157
|
This is a community effort project. In the truest sense, this project started as an open source project from [cron.js](http://github.com/padolsey/cron.js) and grew into something else. Other people have contributed code, time, and oversight to the project. At this point there are too many to name here so we'll just say thanks.
|
|
162
158
|
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExclusiveParametersError = void 0;
|
|
4
|
+
class ExclusiveParametersError extends Error {
|
|
5
|
+
constructor(param1, param2) {
|
|
6
|
+
super(`You can't specify both ${param1} and ${param2}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.ExclusiveParametersError = ExclusiveParametersError;
|
|
10
|
+
//# sourceMappingURL=errors.js.map
|
package/dist/job.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export declare class CronJob {
|
|
|
10
10
|
onComplete?: (...args: any) => void;
|
|
11
11
|
private _timeout?;
|
|
12
12
|
private _callbacks;
|
|
13
|
-
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?:
|
|
13
|
+
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams['unrefTimeout']);
|
|
14
|
+
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: null, context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: CronJobParams['utcOffset'], unrefTimeout?: CronJobParams['unrefTimeout']);
|
|
14
15
|
static from(params: CronJobParams): CronJob;
|
|
15
16
|
private _fnWrap;
|
|
16
17
|
addCallback(callback: (...args: any) => void): void;
|
package/dist/job.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CronJob = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
5
6
|
const time_1 = require("./time");
|
|
6
7
|
class CronJob {
|
|
7
8
|
constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout) {
|
|
@@ -11,7 +12,18 @@ class CronJob {
|
|
|
11
12
|
this.runOnce = false;
|
|
12
13
|
this._callbacks = [];
|
|
13
14
|
this.context = context || this;
|
|
14
|
-
|
|
15
|
+
if (timeZone != null && utcOffset != null) {
|
|
16
|
+
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
17
|
+
}
|
|
18
|
+
if (timeZone != null) {
|
|
19
|
+
this.cronTime = new time_1.CronTime(cronTime, timeZone, null);
|
|
20
|
+
}
|
|
21
|
+
else if (utcOffset != null) {
|
|
22
|
+
this.cronTime = new time_1.CronTime(cronTime, null, utcOffset);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
|
|
26
|
+
}
|
|
15
27
|
if (unrefTimeout != null) {
|
|
16
28
|
this.unrefTimeout = unrefTimeout;
|
|
17
29
|
}
|
|
@@ -30,7 +42,18 @@ class CronJob {
|
|
|
30
42
|
this.start();
|
|
31
43
|
}
|
|
32
44
|
static from(params) {
|
|
33
|
-
|
|
45
|
+
if (params.timeZone != null && params.utcOffset != null) {
|
|
46
|
+
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
47
|
+
}
|
|
48
|
+
if (params.timeZone != null) {
|
|
49
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
|
|
50
|
+
}
|
|
51
|
+
else if (params.utcOffset != null) {
|
|
52
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
|
|
56
|
+
}
|
|
34
57
|
}
|
|
35
58
|
_fnWrap(cmd) {
|
|
36
59
|
var _a, _b;
|
package/dist/time.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DateTime, Zone } from 'luxon';
|
|
2
|
+
import { CronJobParams } from './types/cron.types';
|
|
2
3
|
export declare class CronTime {
|
|
3
4
|
source: string | DateTime;
|
|
4
|
-
|
|
5
|
-
utcOffset?: number
|
|
5
|
+
timeZone?: string;
|
|
6
|
+
utcOffset?: number;
|
|
6
7
|
realDate: boolean;
|
|
7
8
|
private second;
|
|
8
9
|
private minute;
|
|
@@ -10,7 +11,8 @@ export declare class CronTime {
|
|
|
10
11
|
private dayOfMonth;
|
|
11
12
|
private month;
|
|
12
13
|
private dayOfWeek;
|
|
13
|
-
constructor(source:
|
|
14
|
+
constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
|
|
15
|
+
constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
|
|
14
16
|
private _getWeekDay;
|
|
15
17
|
private _verifyParse;
|
|
16
18
|
sendAt(): DateTime;
|
|
@@ -18,7 +20,7 @@ export declare class CronTime {
|
|
|
18
20
|
getTimeout(): number;
|
|
19
21
|
toString(): string;
|
|
20
22
|
toJSON(): string[];
|
|
21
|
-
getNextDateFrom(start: Date | DateTime,
|
|
23
|
+
getNextDateFrom(start: Date | DateTime, timeZone?: string | Zone): DateTime;
|
|
22
24
|
private _findPreviousDSTJump;
|
|
23
25
|
private _checkTimeInSkippedRange;
|
|
24
26
|
private _checkTimeInSkippedRangeSingleHour;
|
package/dist/time.js
CHANGED
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CronTime = void 0;
|
|
4
4
|
const luxon_1 = require("luxon");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class CronTime {
|
|
8
|
-
constructor(source,
|
|
9
|
+
constructor(source, timeZone, utcOffset) {
|
|
9
10
|
this.realDate = false;
|
|
10
11
|
this.second = {};
|
|
11
12
|
this.minute = {};
|
|
@@ -13,12 +14,15 @@ class CronTime {
|
|
|
13
14
|
this.dayOfMonth = {};
|
|
14
15
|
this.month = {};
|
|
15
16
|
this.dayOfWeek = {};
|
|
16
|
-
if (
|
|
17
|
-
|
|
17
|
+
if (timeZone != null && utcOffset != null) {
|
|
18
|
+
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
|
|
19
|
+
}
|
|
20
|
+
if (timeZone) {
|
|
21
|
+
const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
|
|
18
22
|
if (!dt.isValid) {
|
|
19
23
|
throw new Error('Invalid timezone.');
|
|
20
24
|
}
|
|
21
|
-
this.
|
|
25
|
+
this.timeZone = timeZone;
|
|
22
26
|
}
|
|
23
27
|
if (utcOffset != null) {
|
|
24
28
|
this.utcOffset = utcOffset;
|
|
@@ -69,26 +73,16 @@ class CronTime {
|
|
|
69
73
|
let date = this.realDate && this.source instanceof luxon_1.DateTime
|
|
70
74
|
? this.source
|
|
71
75
|
: luxon_1.DateTime.local();
|
|
72
|
-
if (this.
|
|
73
|
-
date = date.setZone(this.
|
|
74
|
-
}
|
|
75
|
-
if (this.utcOffset
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
Math.abs(this.utcOffset - offsetHours * 60)
|
|
83
|
-
: 0;
|
|
84
|
-
const offsetMinsStr = offsetMins >= 10 ? offsetMins : `0${offsetMins}`;
|
|
85
|
-
let utcZone = 'UTC';
|
|
86
|
-
if (parseInt(this.utcOffset) < 0) {
|
|
87
|
-
utcZone += `${offsetHours === 0 ? '-0' : offsetHours}:${offsetMinsStr}`;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
utcZone += `+${offsetHours}:${offsetMinsStr}`;
|
|
91
|
-
}
|
|
76
|
+
if (this.timeZone) {
|
|
77
|
+
date = date.setZone(this.timeZone);
|
|
78
|
+
}
|
|
79
|
+
if (this.utcOffset !== undefined) {
|
|
80
|
+
const sign = this.utcOffset < 0 ? '-' : '+';
|
|
81
|
+
const offsetHours = Math.trunc(this.utcOffset / 60);
|
|
82
|
+
const offsetHoursStr = String(Math.abs(offsetHours)).padStart(2, '0');
|
|
83
|
+
const offsetMins = Math.abs(this.utcOffset - offsetHours * 60);
|
|
84
|
+
const offsetMinsStr = String(offsetMins).padStart(2, '0');
|
|
85
|
+
const utcZone = `UTC${sign}${offsetHoursStr}:${offsetMinsStr}`;
|
|
92
86
|
date = date.setZone(utcZone);
|
|
93
87
|
if (!date.isValid) {
|
|
94
88
|
throw new Error('ERROR: You specified an invalid UTC offset.');
|
|
@@ -123,15 +117,15 @@ class CronTime {
|
|
|
123
117
|
return this._wcOrAll(unit);
|
|
124
118
|
});
|
|
125
119
|
}
|
|
126
|
-
getNextDateFrom(start,
|
|
120
|
+
getNextDateFrom(start, timeZone) {
|
|
127
121
|
var _a;
|
|
128
122
|
if (start instanceof Date) {
|
|
129
123
|
start = luxon_1.DateTime.fromJSDate(start);
|
|
130
124
|
}
|
|
131
125
|
let date = start;
|
|
132
126
|
const firstDate = start.toMillis();
|
|
133
|
-
if (
|
|
134
|
-
date = date.setZone(
|
|
127
|
+
if (timeZone) {
|
|
128
|
+
date = date.setZone(timeZone);
|
|
135
129
|
}
|
|
136
130
|
if (!this.realDate) {
|
|
137
131
|
if (date.millisecond > 0) {
|
|
@@ -147,7 +141,7 @@ class CronTime {
|
|
|
147
141
|
if (date > maxMatch) {
|
|
148
142
|
throw new Error(`Something went wrong. No execution date was found in the next 8 years.
|
|
149
143
|
Please provide the following string if you would like to help debug:
|
|
150
|
-
Time Zone: ${(_a =
|
|
144
|
+
Time Zone: ${(_a = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
|
|
151
145
|
}
|
|
152
146
|
if (!(date.month in this.month) &&
|
|
153
147
|
Object.keys(this.month).length !== 12) {
|
|
@@ -4,17 +4,22 @@ import { DateTime } from 'luxon';
|
|
|
4
4
|
import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants';
|
|
5
5
|
import { CronJob } from '../job';
|
|
6
6
|
import { IntRange } from './utils';
|
|
7
|
-
|
|
7
|
+
interface BaseCronJobParams {
|
|
8
8
|
cronTime: string | Date | DateTime;
|
|
9
9
|
onTick: CronCommand;
|
|
10
10
|
onComplete?: CronCommand | null;
|
|
11
11
|
start?: boolean | null;
|
|
12
|
-
timeZone?: string | null;
|
|
13
12
|
context?: unknown | null;
|
|
14
13
|
runOnInit?: boolean | null;
|
|
15
|
-
utcOffset?: string | number | null;
|
|
16
14
|
unrefTimeout?: boolean | null;
|
|
17
15
|
}
|
|
16
|
+
export type CronJobParams = BaseCronJobParams & ({
|
|
17
|
+
timeZone?: string | null;
|
|
18
|
+
utcOffset?: never;
|
|
19
|
+
} | {
|
|
20
|
+
timeZone?: never;
|
|
21
|
+
utcOffset?: number | null;
|
|
22
|
+
});
|
|
18
23
|
export type CronCommand = ((this: CronJob | any) => void) | string | {
|
|
19
24
|
command: string;
|
|
20
25
|
args?: readonly string[] | null;
|
|
@@ -36,3 +41,4 @@ export type HourRange = IntRange<(typeof CONSTRAINTS)['hour'][0], (typeof CONSTR
|
|
|
36
41
|
export type DayOfMonthRange = IntRange<(typeof CONSTRAINTS)['dayOfMonth'][0], (typeof CONSTRAINTS)['dayOfMonth'][1]>;
|
|
37
42
|
export type MonthRange = IntRange<(typeof CONSTRAINTS)['month'][0], (typeof CONSTRAINTS)['month'][1]>;
|
|
38
43
|
export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>;
|
|
44
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.9",
|
|
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"
|