cron 3.3.2 → 3.5.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 CHANGED
@@ -1,3 +1,36 @@
1
+ ## [3.5.0](https://github.com/kelektiv/node-cron/compare/v3.4.0...v3.5.0) (2025-01-10)
2
+
3
+ ### ✨ Features
4
+
5
+ * throw instead of silently rewriting invalid cron expressions ([#937](https://github.com/kelektiv/node-cron/issues/937)) ([dcc5b93](https://github.com/kelektiv/node-cron/commit/dcc5b939fb08a806793799019c9f256bd137c33d))
6
+
7
+ ### ⚙️ Continuous Integrations
8
+
9
+ * **action:** update step-security/harden-runner action to v2.10.3 ([#943](https://github.com/kelektiv/node-cron/issues/943)) ([cd7ee9f](https://github.com/kelektiv/node-cron/commit/cd7ee9f62fbdd16ec150e9e5aa69d8852f5b3dcb))
10
+
11
+ ### ♻️ Chores
12
+
13
+ * **deps:** update dependency [@types](https://github.com/types)/node to v20.17.12 ([2a867f9](https://github.com/kelektiv/node-cron/commit/2a867f9c34c216ac04ce8bce34e0e16578f7dd0c))
14
+ * **deps:** update dependency [@types](https://github.com/types)/node to v22 ([#900](https://github.com/kelektiv/node-cron/issues/900)) ([f7548bd](https://github.com/kelektiv/node-cron/commit/f7548bd3b6981514abd174341b39813d0d6f239a))
15
+
16
+ ## [3.4.0](https://github.com/kelektiv/node-cron/compare/v3.3.2...v3.4.0) (2025-01-09)
17
+
18
+ ### ✨ Features
19
+
20
+ * error handling on ticks ([#861](https://github.com/kelektiv/node-cron/issues/861)) ([0d3161f](https://github.com/kelektiv/node-cron/commit/0d3161ff7831752edade0333e4ae9ce70e50ac0b)), closes [#426](https://github.com/kelektiv/node-cron/issues/426)
21
+
22
+ ### 📚 Documentation
23
+
24
+ * **contributing:** add "Submitting a Pull Request" & "Coding Rules" sections ([#936](https://github.com/kelektiv/node-cron/issues/936)) ([ddd8988](https://github.com/kelektiv/node-cron/commit/ddd89881bcb2f3737e1ea50296fe25294d112bdd))
25
+
26
+ ### ♻️ Chores
27
+
28
+ * **deps:** lock file maintenance ([494b4bf](https://github.com/kelektiv/node-cron/commit/494b4bf5d61ba2b4d57e7b46cd433bcb4577d525))
29
+ * **deps:** update dependency [@types](https://github.com/types)/node to v20.17.11 ([2978e92](https://github.com/kelektiv/node-cron/commit/2978e92ba1a26dfe8de7eb6c1ee4b3847cf18279))
30
+ * **deps:** update dependency lint-staged to v15.3.0 ([11f9bad](https://github.com/kelektiv/node-cron/commit/11f9badb761d06cd74a543116854094559acb813))
31
+ * **deps:** update semantic-release related packages ([b830bdb](https://github.com/kelektiv/node-cron/commit/b830bdb41df2ebc48d3510ffd71f3d59255eaf11))
32
+ * **deps:** update tests (major) ([#826](https://github.com/kelektiv/node-cron/issues/826)) ([e47fd5a](https://github.com/kelektiv/node-cron/commit/e47fd5aaefb5452fd06e4a76b847110a13832456))
33
+
1
34
  ## [3.3.2](https://github.com/kelektiv/node-cron/compare/v3.3.1...v3.3.2) (2024-12-30)
2
35
 
3
36
  ### 🐛 Bug Fixes
package/README.md CHANGED
@@ -196,6 +196,8 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
196
196
 
197
197
  - `waitForCompletion`: [OPTIONAL] - If `true`, no additional instances of the `onTick` callback function will run until the current onTick callback has completed. Any new scheduled executions that occur while the current callback is running will be skipped entirely. Default is `false`.
198
198
 
199
+ - `errorHandler`: [OPTIONAL] - Function to handle any exceptions that occur in the `onTick` method.
200
+
199
201
  #### Methods
200
202
 
201
203
  - `from` (static): Create a new CronJob object providing arguments as an object. See argument names and descriptions above.
@@ -6,20 +6,6 @@ export declare const CONSTRAINTS: Readonly<{
6
6
  readonly month: readonly [1, 12];
7
7
  readonly dayOfWeek: readonly [0, 7];
8
8
  }>;
9
- export declare const MONTH_CONSTRAINTS: Readonly<{
10
- readonly 1: 31;
11
- readonly 2: 29;
12
- readonly 3: 31;
13
- readonly 4: 30;
14
- readonly 5: 31;
15
- readonly 6: 30;
16
- readonly 7: 31;
17
- readonly 8: 31;
18
- readonly 9: 30;
19
- readonly 10: 31;
20
- readonly 11: 30;
21
- readonly 12: 31;
22
- }>;
23
9
  export declare const PARSE_DEFAULTS: Readonly<{
24
10
  readonly second: "0";
25
11
  readonly minute: "*";
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RE_RANGE = exports.RE_WILDCARDS = exports.PRESETS = exports.TIME_UNITS_LEN = exports.TIME_UNITS = exports.TIME_UNITS_MAP = exports.ALIASES = exports.PARSE_DEFAULTS = exports.MONTH_CONSTRAINTS = exports.CONSTRAINTS = void 0;
3
+ exports.RE_RANGE = exports.RE_WILDCARDS = exports.PRESETS = exports.TIME_UNITS_LEN = exports.TIME_UNITS = exports.TIME_UNITS_MAP = exports.ALIASES = exports.PARSE_DEFAULTS = exports.CONSTRAINTS = void 0;
4
4
  exports.CONSTRAINTS = Object.freeze({
5
5
  second: [0, 59],
6
6
  minute: [0, 59],
@@ -9,20 +9,6 @@ exports.CONSTRAINTS = Object.freeze({
9
9
  month: [1, 12],
10
10
  dayOfWeek: [0, 7]
11
11
  });
12
- exports.MONTH_CONSTRAINTS = Object.freeze({
13
- 1: 31,
14
- 2: 29,
15
- 3: 31,
16
- 4: 30,
17
- 5: 31,
18
- 6: 30,
19
- 7: 31,
20
- 8: 31,
21
- 9: 30,
22
- 10: 31,
23
- 11: 30,
24
- 12: 31
25
- });
26
12
  exports.PARSE_DEFAULTS = Object.freeze({
27
13
  second: '0',
28
14
  minute: '*',
package/dist/job.d.ts CHANGED
@@ -9,12 +9,13 @@ export declare class CronJob<OC extends CronOnCompleteCommand | null = null, C =
9
9
  context: CronContext<C>;
10
10
  onComplete?: WithOnComplete<OC> extends true ? CronOnCompleteCallback : undefined;
11
11
  waitForCompletion: boolean;
12
+ errorHandler?: CronJobParams<OC, C>['errorHandler'];
12
13
  private _isCallbackRunning;
13
14
  private _timeout?;
14
15
  private _callbacks;
15
16
  get isCallbackRunning(): boolean;
16
- 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']);
17
- 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']);
17
+ 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
+ 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
19
  static from<OC extends CronOnCompleteCommand | null = null, C = null>(params: CronJobParams<OC, C>): CronJob<OC, C>;
19
20
  private _fnWrap;
20
21
  addCallback(callback: CronCallback<C, WithOnComplete<OC>>): void;
package/dist/job.js CHANGED
@@ -17,7 +17,7 @@ class CronJob {
17
17
  get isCallbackRunning() {
18
18
  return this._isCallbackRunning;
19
19
  }
20
- constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion) {
20
+ constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion, errorHandler) {
21
21
  this.running = false;
22
22
  this.unrefTimeout = false;
23
23
  this.lastExecution = null;
@@ -27,6 +27,7 @@ class CronJob {
27
27
  this._callbacks = [];
28
28
  this.context = (context !== null && context !== void 0 ? context : this);
29
29
  this.waitForCompletion = Boolean(waitForCompletion);
30
+ this.errorHandler = errorHandler;
30
31
  if (timeZone != null && utcOffset != null) {
31
32
  throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
32
33
  }
@@ -61,13 +62,13 @@ class CronJob {
61
62
  throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
62
63
  }
63
64
  if (params.timeZone != null) {
64
- return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion);
65
+ 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);
65
66
  }
66
67
  else if (params.utcOffset != null) {
67
- return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion);
68
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion, params.errorHandler);
68
69
  }
69
70
  else {
70
- return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion);
71
+ 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);
71
72
  }
72
73
  }
73
74
  _fnWrap(cmd) {
@@ -118,7 +119,10 @@ class CronJob {
118
119
  }
119
120
  }
120
121
  catch (error) {
121
- console.error('[Cron] error in callback', error);
122
+ if (this.errorHandler != null)
123
+ this.errorHandler(error);
124
+ else
125
+ console.error('[Cron] error in callback', error);
122
126
  }
123
127
  finally {
124
128
  this._isCallbackRunning = false;
package/dist/time.d.ts CHANGED
@@ -14,7 +14,6 @@ export declare class CronTime {
14
14
  constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
15
15
  constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
16
16
  private _getWeekDay;
17
- private _verifyParse;
18
17
  sendAt(): DateTime;
19
18
  sendAt(i: number): DateTime[];
20
19
  getTimeout(): number;
package/dist/time.js CHANGED
@@ -4,7 +4,6 @@ exports.CronTime = void 0;
4
4
  const luxon_1 = require("luxon");
5
5
  const constants_1 = require("./constants");
6
6
  const errors_1 = require("./errors");
7
- const utils_1 = require("./utils");
8
7
  class CronTime {
9
8
  constructor(source, timeZone, utcOffset) {
10
9
  this.realDate = false;
@@ -35,40 +34,11 @@ class CronTime {
35
34
  else {
36
35
  this.source = source;
37
36
  this._parse(this.source);
38
- this._verifyParse();
39
37
  }
40
38
  }
41
39
  _getWeekDay(date) {
42
40
  return date.weekday === 7 ? 0 : date.weekday;
43
41
  }
44
- _verifyParse() {
45
- const months = (0, utils_1.getRecordKeys)(this.month);
46
- const daysOfMonth = (0, utils_1.getRecordKeys)(this.dayOfMonth);
47
- let isOk = false;
48
- let lastWrongMonth = null;
49
- for (const m of months) {
50
- const con = constants_1.MONTH_CONSTRAINTS[m];
51
- for (const day of daysOfMonth) {
52
- if (day <= con) {
53
- isOk = true;
54
- }
55
- }
56
- if (!isOk) {
57
- lastWrongMonth = m;
58
- console.warn(`Month '${m}' is limited to '${con}' days.`);
59
- }
60
- }
61
- if (!isOk && lastWrongMonth !== null) {
62
- const notOkCon = constants_1.MONTH_CONSTRAINTS[lastWrongMonth];
63
- for (const notOkDay of daysOfMonth) {
64
- if (notOkDay > notOkCon) {
65
- delete this.dayOfMonth[notOkDay];
66
- const fixedDay = (notOkDay % notOkCon);
67
- this.dayOfMonth[fixedDay] = true;
68
- }
69
- }
70
- }
71
- }
72
42
  sendAt(i) {
73
43
  let date = this.realDate && this.source instanceof luxon_1.DateTime
74
44
  ? this.source
@@ -12,6 +12,7 @@ interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C =
12
12
  runOnInit?: boolean | null;
13
13
  unrefTimeout?: boolean | null;
14
14
  waitForCompletion?: boolean | null;
15
+ errorHandler?: ((error: unknown) => void) | null;
15
16
  }
16
17
  export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> & ({
17
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": "3.3.2",
4
+ "version": "3.5.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"
@@ -34,25 +34,25 @@
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",
37
- "@semantic-release/commit-analyzer": "13.0.0",
37
+ "@semantic-release/commit-analyzer": "13.0.1",
38
38
  "@semantic-release/git": "10.0.1",
39
39
  "@semantic-release/github": "11.0.1",
40
40
  "@semantic-release/npm": "12.0.1",
41
- "@semantic-release/release-notes-generator": "14.0.2",
41
+ "@semantic-release/release-notes-generator": "14.0.3",
42
42
  "@types/jest": "29.5.14",
43
- "@types/node": "20.17.10",
43
+ "@types/node": "22.10.5",
44
44
  "@types/sinon": "17.0.3",
45
- "chai": "4.5.0",
45
+ "chai": "5.1.2",
46
46
  "eslint": "8.57.1",
47
47
  "eslint-config-prettier": "9.1.0",
48
48
  "eslint-plugin-jest": "27.9.0",
49
49
  "eslint-plugin-prettier": "5.2.1",
50
50
  "husky": "9.1.7",
51
51
  "jest": "29.7.0",
52
- "lint-staged": "15.2.11",
52
+ "lint-staged": "15.3.0",
53
53
  "prettier": "3.4.2",
54
- "semantic-release": "24.2.0",
55
- "sinon": "17.0.2",
54
+ "semantic-release": "24.2.1",
55
+ "sinon": "19.0.2",
56
56
  "ts-jest": "29.2.5",
57
57
  "typescript": "5.7.2",
58
58
  "typescript-eslint": "7.18.0"