cron 2.3.1 → 2.4.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,22 +1,91 @@
1
- ## [v2.0.0] - 2022-05-03
1
+ ## [2.4.0](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.4.0) (2023-07-24)
2
+
3
+
4
+ ### ✨ Features
5
+
6
+ * import type definitions from [@types](https://github.com/types)/cron ([d8a2f14](https://github.com/kelektiv/node-cron/commit/d8a2f140b59f063897dd20b7bb4dc7f599d2435b))
7
+
8
+
9
+ ### 🐛 Bug Fixes
10
+
11
+ * don't start job in setTime if it wasn't running ([7e26c23](https://github.com/kelektiv/node-cron/commit/7e26c23e06277bfeb04525c71b67703392dbb8b2))
12
+
13
+
14
+ ### 🛠 Builds
15
+
16
+ * **npm:** ship type definitions with releases ([0b663a8](https://github.com/kelektiv/node-cron/commit/0b663a8584f87cbec63042a4c217f43f38869fc4))
17
+
18
+
19
+ ### 🚨 Tests
20
+
21
+ * add test case for [#598](https://github.com/kelektiv/node-cron/issues/598) fix ([4322ef2](https://github.com/kelektiv/node-cron/commit/4322ef29fa8af201aed5cdf8b829d411311fe025))
22
+ * don't stop/start job before using setTime ([f0d5d3f](https://github.com/kelektiv/node-cron/commit/f0d5d3f32eddb8fd77b84438fe471fd374b34566))
23
+
24
+
25
+ ### ⚙️ Continuous Integrations
26
+
27
+ * add support for beta & maintenance releases ([#677](https://github.com/kelektiv/node-cron/issues/677)) ([c6fc842](https://github.com/kelektiv/node-cron/commit/c6fc8429e905b38b05ba428e0df4a0fea273614a))
28
+ * setup conventional commits & release automation ([#673](https://github.com/kelektiv/node-cron/issues/673)) ([c6f39ff](https://github.com/kelektiv/node-cron/commit/c6f39ff384041b7f91566fc935a9b961d453dd14))
29
+
30
+
31
+ ### ♻️ Chores
32
+
33
+ * update default branch name ([#678](https://github.com/kelektiv/node-cron/issues/678)) ([7471e95](https://github.com/kelektiv/node-cron/commit/7471e95cb7433b4f29cfa68da0a652ec8cf630b6))
34
+ * wrap setTime tests in describe and move down ([31989e0](https://github.com/kelektiv/node-cron/commit/31989e06f939bf1e9dbc6c0b6fc62c0a7144b9eb))
35
+
36
+ ## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)
37
+
38
+ ### Added
39
+
40
+ - Logo!
41
+ - New test cases
42
+
43
+ ### Fixed
44
+
45
+ - Linting issues
46
+
47
+ ## [v2.3.0](https://github.com/kelektiv/node-cron/compare/v2.2.0...v2.3.0) (2023-03-14)
48
+
49
+ ### Fixed
50
+
51
+ - Some small bugs
52
+
53
+ ### Changed
54
+
55
+ - Refactored get next date function
56
+
57
+ ## [v2.2.0](https://github.com/kelektiv/node-cron/compare/v2.1.0...v2.2.0) (2023-01-09)
58
+
59
+ ### Changed
60
+
61
+ - Updated Luxon dependency
62
+ - Updated unit tests to be compatible with new Luxon version
63
+
64
+ ## [v2.1.0](https://github.com/kelektiv/node-cron/compare/v2.0.0...v2.1.0) (2022-07-14)
65
+
66
+ ### Changed
67
+
68
+ - "Maximum iterations" will direct the user to refer to a single canonical issue instead of creating a new one
69
+
70
+ ## [v2.0.0](https://github.com/kelektiv/node-cron/compare/v1.8.2...v2.0.0) (2022-05-03)
2
71
  - Upgrade vulnerable dependencies
3
72
  - Move from moment.js to luxon (breaking change)
4
73
 
5
- ## [v1.8.2] - 2020-01-24
74
+ ## [v1.8.2](https://github.com/kelektiv/node-cron/compare/v1.8.1...v1.8.2) (2020-01-24)
6
75
  - Fix syntax parsing bug
7
76
 
8
- ## [v1.8.1] - 2020-01-19
77
+ ## [v1.8.1](https://github.com/kelektiv/node-cron/compare/v1.8.0...v1.8.1) (2020-01-19)
9
78
  - Revert TS definition defaulting to DefinitelyTyped definitions.
10
79
 
11
- ## [v1.8.0] - 2020-01-19
80
+ ## [v1.8.0](https://github.com/kelektiv/node-cron/compare/v1.7.1...v1.8.0) (2020-01-19)
12
81
  - GH-454 - Range upper limit should default to highest value when step is provided by Noah May <noahmouse2011@gmail.com> in d36dc9581f9f68580a2016b368f8002a9f1e357d
13
82
 
14
- ## [v1.7.1] - 2019-04-26
83
+ ## [v1.7.1](https://github.com/kelektiv/node-cron/compare/v1.7.0...v1.7.1) (2019-04-26)
15
84
  - GH-416 - Fix issue where next execution time is incorrect in some cases in Naoya Inada <naoina@kuune.org> in c08522ff80b3987843e9930c307b76d5fe38b5dc
16
85
 
17
- ## [v1.7.0] - 2019-03-19
86
+ ## [v1.7.0](https://github.com/kelektiv/node-cron/compare/v1.6.0...v1.7.0) (2019-03-19)
18
87
  - GH-408 - DST issue by Shua Talansky <shua@bitbean.com> in 1e971fd6dfa6ba4b0469d99dd64e6c31189d17d3 and 849a2467d16216a9dfa818c57cc26be6b6d0899b
19
88
 
20
- ## [v1.6.0] - 2018-11-15
89
+ ## [v1.6.0](https://github.com/kelektiv/node-cron/compare/v1.5.1...v1.6.0) (2018-11-15)
21
90
  - GH-393, GH-394 - Remove hard limit on max iters in favor of a timeout by Nick Campbell <nicholas.j.campbell@gmail.com> in 57632b0c06c56e82f40b740b8d7986be43842735
22
91
  - GH-390 - better handling of real dates which are in the past by Nick Campbell <nicholas.j.campbell@gmail.com> in 7cbcc984aea6ec063e38829f68eb9bc0dfb1c775
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -49,7 +49,7 @@ var job = new CronJob(
49
49
 
50
50
  Note - In the example above, the 4th parameter of `CronJob()` automatically starts the job on initialization. If this parameter is falsy or not provided, the job needs to be explicitly started using `job.start()`.
51
51
 
52
- There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/master/examples)
52
+ There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/main/examples)
53
53
 
54
54
  ## Available Cron patterns
55
55
 
@@ -71,11 +71,12 @@ When specifying your cron values you'll need to make sure that your values fall
71
71
  - Minutes: 0-59
72
72
  - Hours: 0-23
73
73
  - Day of Month: 1-31
74
- - Months: 0-11 (Jan-Dec)
74
+ - Months: 0-11 (Jan-Dec) <-- currently different from Unix `cron`!
75
75
  - Day of Week: 0-6 (Sun-Sat)
76
76
 
77
77
  ## Gotchas
78
78
 
79
+ - Months are indexed as 0-11 instead of 1-12. This is different from Unix `cron` and is planned to updated to match Unix `cron` in v3.0.0 of `node-cron`.
79
80
  - Millisecond level granularity in JS `Date` or Luxon `DateTime` objects: Because computers take time to do things, there may be some delay in execution. This should be on the order of milliseconds. This module doesn't allow MS level granularity for the regular cron syntax, but _does_ allow you to specify a real date of execution in either a javascript `Date` object or a Luxon `DateTime` object. When this happens you may find that you aren't able to execute a job that _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution above. This wont be the same for everyone because of compute speed. When we tried it locally we saw that somewhere around the 4-5 ms mark was where we got consistent ticks using real dates, but anything less than that would result in an exception. This could be really confusing. We could restrict the granularity for all dates to seconds, but felt that it wasn't a huge problem so long as you were made aware. If this becomes more of an issue, We can revisit it.
80
81
  - Arrow Functions for `onTick`: Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get the `this` context of the cronjob. You can read a little more in issue [GH-47](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775)
81
82
 
@@ -88,15 +89,15 @@ Parameter Based
88
89
  - `sendAt` - tells you when a `CronTime` will be run.
89
90
  - `timeout` - tells you when the next timeout is.
90
91
  - `CronJob`
91
- - `constructor(cronTime, onTick, onComplete, start, timezone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
92
+ - `constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
92
93
  - `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
93
94
  - `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.
94
95
  - `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.
95
96
  - `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.
96
- - `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
97
+ - `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 all time zones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
97
98
  - `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.
98
99
  - `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.
99
- - `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your timezone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
100
+ - `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
100
101
  - `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.
101
102
  - `start` - Runs your job.
102
103
  - `stop` - Stops your job.
package/lib/cron.js CHANGED
File without changes
package/lib/job.js CHANGED
File without changes
package/lib/time.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cron",
3
3
  "description": "Cron jobs for your node",
4
- "version": "2.3.1",
4
+ "version": "2.4.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"
@@ -14,12 +14,24 @@
14
14
  "scripts": {
15
15
  "lint": "eslint {lib,tests}/*.js",
16
16
  "test": "jest --coverage",
17
- "test:watch": "jest --watch --coverage"
17
+ "test:watch": "jest --watch --coverage",
18
+ "prepare": "husky install",
19
+ "release": "semantic-release"
18
20
  },
21
+ "types": "types/index.d.ts",
19
22
  "dependencies": {
20
23
  "luxon": "^3.2.1"
21
24
  },
22
25
  "devDependencies": {
26
+ "@commitlint/cli": "~17.6.6",
27
+ "@insurgentlab/commitlint-config": "^18.1.0",
28
+ "@insurgentlab/conventional-changelog-preset": "~6.0.3",
29
+ "@semantic-release/changelog": "~6.0.x",
30
+ "@semantic-release/commit-analyzer": "~9.0.x",
31
+ "@semantic-release/git": "~10.0.x",
32
+ "@semantic-release/github": "~8.1.x",
33
+ "@semantic-release/npm": "~10.0.x",
34
+ "@semantic-release/release-notes-generator": "~11.0.x",
23
35
  "chai": "~4.2.x",
24
36
  "eslint": "~8.36.x",
25
37
  "eslint-config-prettier": "^8.7.x",
@@ -29,8 +41,10 @@
29
41
  "eslint-plugin-n": "~15.6.x",
30
42
  "eslint-plugin-prettier": "~4.2.x",
31
43
  "eslint-plugin-promise": "~6.1.x",
44
+ "husky": "^8.0.3",
32
45
  "jest": "~29.5.x",
33
46
  "prettier": "~2.8.x",
47
+ "semantic-release": "~21.0.x",
34
48
  "sinon": "^15.0.x"
35
49
  },
36
50
  "keywords": [
@@ -76,6 +90,7 @@
76
90
  },
77
91
  "files": [
78
92
  "lib",
93
+ "types",
79
94
  "CHANGELOG.md",
80
95
  "LICENSE",
81
96
  "README.md"
@@ -0,0 +1,181 @@
1
+ // Type definitions for cron 2.0
2
+ // Project: https://www.npmjs.com/package/cron
3
+ // Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>
4
+ // Lundarl Gholoi <https://github.com/winup>
5
+ // koooge <https://github.com/koooge>
6
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
+
8
+ /// <reference types="node" />
9
+
10
+ import { SpawnOptions } from 'child_process';
11
+ import { DateTime } from 'luxon';
12
+
13
+ export declare type CronCommand =
14
+ | (() => void)
15
+ | string
16
+ | {
17
+ command: string;
18
+ args?: ReadonlyArray<string> | undefined;
19
+ options?: SpawnOptions | undefined;
20
+ };
21
+
22
+ export declare class CronTime {
23
+ /**
24
+ * Create a new ```CronTime```.
25
+ * @param source The time to fire off your job. This can be in the form of cron syntax, a JS ```Date``` object, or a luxon ```DateTime``` object.
26
+ * @param zone Timezone name. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone).
27
+ * @param utcOffset UTC offset. Don't use both ```zone``` and ```utcOffset``` together or weird things may happen.
28
+ */
29
+ constructor(
30
+ source: string | Date | DateTime,
31
+ zone?: string,
32
+ utcOffset?: string | number
33
+ );
34
+
35
+ /**
36
+ * Tells you when ```CronTime``` will be run.
37
+ */
38
+ public sendAt(): DateTime;
39
+ /**
40
+ * Tells you when ```CronTime``` will be run.
41
+ * @param i Indicate which turn of run after now. If not given return next run time.
42
+ * @returns A ```DateTime``` when the source passed in the constructor is a ```Date``` or a ```DateTime``` and an array of ```DateTime``` when the source is a string.
43
+ */
44
+ public sendAt(i?: number): DateTime | DateTime[];
45
+ /**
46
+ * Get the number of milliseconds in the future at which to fire our callbacks.
47
+ */
48
+ public getTimeout(): number;
49
+ }
50
+
51
+ export declare interface CronJobParameters {
52
+ /**
53
+ * The time to fire off your job. This can be in the form of cron syntax, a JS ```Date``` object, or a luxon ```DateTime``` object.
54
+ */
55
+ cronTime: string | Date | DateTime;
56
+ /**
57
+ * 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.
58
+ */
59
+ onTick: CronCommand;
60
+ /**
61
+ * 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.
62
+ */
63
+ onComplete?: CronCommand | null | undefined;
64
+ /**
65
+ * 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.
66
+ */
67
+ start?: boolean | undefined;
68
+ /**
69
+ * Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone). Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.
70
+ */
71
+ timeZone?: string | undefined;
72
+ /**
73
+ * 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.
74
+ */
75
+ context?: any;
76
+ /**
77
+ * This will immediately fire your ```onTick``` function as soon as the requisit initialization has happened. This option is set to ```false``` by default for backwards compatibility.
78
+ */
79
+ runOnInit?: boolean | undefined;
80
+ /**
81
+ * This allows you to specify the offset of your timezone rather than using the ```timeZone``` param. Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.
82
+ */
83
+ utcOffset?: string | number | undefined;
84
+ /**
85
+ * 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.
86
+ */
87
+ unrefTimeout?: boolean | undefined;
88
+ }
89
+
90
+ export declare class CronJob {
91
+ /**
92
+ * Return ```true``` if job is running.
93
+ */
94
+ public running: boolean | undefined;
95
+ /**
96
+ * Function using to fire ```onTick```, default set to an inner private function. Overwrite this only if you have a really good reason to do so.
97
+ */
98
+ public fireOnTick: Function;
99
+
100
+ /**
101
+ * Create a new ```CronJob```.
102
+ * @param cronTime The time to fire off your job. This can be in the form of cron syntax or a JS ```Date``` object.
103
+ * @param onTick The function to fire at the specified time.
104
+ * @param onComplete A function that will fire when the job is complete, when it is stopped.
105
+ * @param startNow 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.
106
+ * @param timeZone Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone).
107
+ * @param context 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.
108
+ * @param runOnInit This will immediately fire your ```onTick``` function as soon as the requisit initialization has happened. This option is set to ```false``` by default for backwards compatibility.
109
+ * @param utcOffset This allows you to specify the offset of your timezone rather than using the ```timeZone``` param. Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.
110
+ * @param unrefTimeout 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.
111
+ */
112
+ constructor(
113
+ cronTime: string | Date | DateTime,
114
+ onTick: CronCommand,
115
+ onComplete?: CronCommand | null,
116
+ startNow?: boolean,
117
+ timeZone?: string,
118
+ context?: any,
119
+ runOnInit?: boolean,
120
+ utcOffset?: string | number,
121
+ unrefTimeout?: boolean
122
+ );
123
+ /**
124
+ * Create a new ```CronJob```.
125
+ * @param options Job parameters.
126
+ */
127
+ constructor(options: CronJobParameters);
128
+
129
+ /**
130
+ * Runs your job.
131
+ */
132
+ public start(): void;
133
+ /**
134
+ * Stops your job.
135
+ */
136
+ public stop(): void;
137
+ /**
138
+ * Change the time for the ```CronJob```.
139
+ * @param time Target time.
140
+ */
141
+ public setTime(time: CronTime): void;
142
+ /**
143
+ * Tells you the last execution date.
144
+ */
145
+ public lastDate(): Date;
146
+ /**
147
+ * Tells you when a ```CronTime``` will be run.
148
+ */
149
+ public nextDate(): DateTime;
150
+ public nextDates(): DateTime;
151
+ /**
152
+ * Tells you when a ```CronTime``` will be run.
153
+ * @param i Indicate which turn of run after now. If not given return next run time.
154
+ * @returns A `DateTime` when the cronTime passed in the constructor is a `Date` or a `DateTime` and an array of `DateTime` when the cronTime is a string.
155
+ */
156
+ public nextDates(i?: number): DateTime | DateTime[];
157
+ /**
158
+ * Add another ```onTick``` function.
159
+ * @param callback Target function.
160
+ */
161
+ public addCallback(callback: Function): void;
162
+ }
163
+
164
+ export declare function job(options: CronJobParameters): CronJob;
165
+ export declare function job(
166
+ cronTime: string | Date | DateTime,
167
+ onTick: () => void,
168
+ onComplete?: CronCommand | null,
169
+ start?: boolean,
170
+ timeZone?: string,
171
+ context?: any,
172
+ runOnInit?: boolean,
173
+ utcOffset?: string | number,
174
+ unrefTimeout?: boolean
175
+ ): CronJob;
176
+ export declare function time(
177
+ source: string | Date | DateTime,
178
+ zone?: string
179
+ ): CronTime;
180
+ export declare function sendAt(cronTime: string | Date | DateTime): DateTime;
181
+ export declare function timeout(cronTime: string | Date | DateTime): number;