cron 1.8.1 → 2.0.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/.editorconfig ADDED
@@ -0,0 +1,5 @@
1
+ root = true
2
+
3
+ [*.{js}]
4
+ indent_style = tab
5
+ indent_size = 2
package/.eslintrc CHANGED
@@ -1,21 +1,14 @@
1
1
  {
2
2
  "extends": ["standard", "prettier", "prettier/standard"],
3
3
  "parserOptions": {
4
- "ecmaVersion": "2017",
5
- "sourceType": "module"
4
+ "ecmaVersion": 2018
6
5
  },
7
6
  "globals": {
8
- "define": true,
9
- "after": true,
10
- "afterEach": true,
11
- "before": true,
12
- "beforeEach": true,
13
- "describe": true,
14
- "expect": true,
15
- "it": true
7
+ "define": "readonly"
16
8
  },
17
9
  "env": {
18
10
  "browser": true,
11
+ "es6": true,
19
12
  "node": true,
20
13
  "jest/globals": true
21
14
  },
@@ -23,6 +16,11 @@
23
16
  "rules": {
24
17
  "space-before-function-paren": 0,
25
18
  "new-cap": 0,
26
- "prettier/prettier": 2
19
+ "prettier/prettier": 2,
20
+ "jest/no-disabled-tests": 1,
21
+ "jest/no-focused-tests": 2,
22
+ "jest/no-identical-title": 2,
23
+ "jest/prefer-to-have-length": 1,
24
+ "jest/valid-expect": 2
27
25
  }
28
26
  }
@@ -0,0 +1,26 @@
1
+ name: Bug
2
+ description: Report a bug found in the bot's source code
3
+ labels: ["🛠 goal: fix"]
4
+ body:
5
+ - type: textarea
6
+ id: description
7
+ attributes:
8
+ label: Description
9
+ description: A brief description of the question or issue, also include what you tried and what didn't work
10
+ validations:
11
+ required: true
12
+ - type: textarea
13
+ id: screenshots
14
+ attributes:
15
+ label: Screenshots
16
+ description: Please add screenshots if applicable
17
+ validations:
18
+ required: false
19
+ - type: textarea
20
+ id: extrainfo
21
+ attributes:
22
+ label: Additional information
23
+ description: Is there anything else we should know about this bug?
24
+ validations:
25
+ required: false
26
+
@@ -0,0 +1,31 @@
1
+ name: Feature request
2
+ description: Suggest features, propose improvements, discuss new ideas
3
+ title: "[FEATURE] <description>"
4
+ labels: ["⭐ goal: addition"]
5
+ body:
6
+ - type: textarea
7
+ id: suggestion
8
+ attributes:
9
+ label: ⭐ Suggestion
10
+ description: A summary of what you'd like to see added or changed
11
+ validations:
12
+ required: true
13
+ - type: textarea
14
+ id: usecases
15
+ attributes:
16
+ label: 💻 Use Cases
17
+ description: |
18
+ What are possible test cases for your suggested feature?
19
+ Are you using any workarounds in the meantime?
20
+ validations:
21
+ required: false
22
+ - type: textarea
23
+ id: relatedproblems
24
+ attributes:
25
+ label: ❌ Related Problems
26
+ description: |
27
+ Is your Request related to a problem?
28
+ Think about linking existing Issues here!
29
+ validations:
30
+ required: false
31
+
@@ -0,0 +1,39 @@
1
+ # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: CI
5
+
6
+ on:
7
+ push:
8
+ branches:
9
+ - master
10
+ pull_request:
11
+ branches:
12
+ - master
13
+
14
+ jobs:
15
+ build:
16
+
17
+ runs-on: ${{ matrix.os }}
18
+
19
+ strategy:
20
+ matrix:
21
+ node: [14.x, 16.x, 18.x]
22
+ os: [ubuntu-latest, windows-latest, macos-latest]
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Use Node.js ${{ matrix.node }}
27
+ uses: actions/setup-node@v1
28
+ with:
29
+ node-version: ${{ matrix.node }}
30
+ - run: npm ci
31
+ - run: npm run build --if-present
32
+ - run: npm test
33
+ env:
34
+ CI: true
35
+ - run: npm run lint
36
+
37
+ - name: Codecov
38
+ if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == '12.x' }}
39
+ uses: codecov/codecov-action@v1.0.6
package/.prettierrc CHANGED
@@ -1,4 +1,7 @@
1
1
  {
2
- "useTabs": true,
3
- "singleQuote": true
2
+ "arrowParens": "avoid",
3
+ "endOfLine": "auto",
4
+ "singleQuote": true,
5
+ "trailingComma": "none",
6
+ "useTabs": true
4
7
  }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [v2.0.0] - 2022-05-03
2
+ - Upgrade vulnerable dependencies
3
+ - Move from moment.js to luxon (breaking change)
4
+
5
+ ## [v1.8.2] - 2020-01-24
6
+ - Fix syntax parsing bug
7
+
1
8
  ## [v1.8.1] - 2020-01-19
2
9
  - Revert TS definition defaulting to DefinitelyTyped definitions.
3
10
 
package/README.md CHANGED
@@ -1,37 +1,42 @@
1
- node-cron
2
- =
1
+ # Looking for maintainers/contributors
3
2
 
4
- [![Build Status](https://travis-ci.org/kelektiv/node-cron.svg?branch=master)](https://travis-ci.org/kelektiv/node-cron)
5
- [![Dependency Status](https://david-dm.org/ncb000gt/node-cron.svg)](https://david-dm.org/ncb000gt/node-cron)
3
+ This project is looking for help! If you're interested in helping with the project please reach out to me [ncb000gt](https://twitter.com/ncb000gt) and let me know. I'd love for it to continue on, but it needs a lot of attention.
4
+
5
+
6
+ # node-cron
7
+
8
+ [![Version](https://badgen.net/npm/v/cron?icon=npm)](https://badgen.net/npm/v/cron)
9
+ [![Build Status](https://badgen.net/github/status/kelektiv/node-cron?icon=github)](https://badgen.net/github/status/kelektiv/node-cron)
10
+ [![Build Checks](https://badgen.net/github/checks/kelektiv/node-cron?icon=github)](https://badgen.net/github/checks/kelektiv/node-cron)
11
+ [![Dependency Status](https://badgen.net/david/dep/kelektiv/node-cron)](https://badgen.net/david/dev/kelektiv/node-cron)
12
+ [![Code Coverage](https://badgen.net/codecov/c/github/kelektiv/node-cron?icon=codecov)](https://badgen.net/codecov/c/github/kelektiv/node-cron)
13
+ [![Known Vulnerabilities](https://snyk.io/test/github/kelektiv/node-cron/badge.svg)](https://snyk.io/test/github/kelektiv/node-cron)
14
+ [![Minified size](https://badgen.net/bundlephobia/min/cron)](https://badgen.net/bundlephobia/min/cron)
15
+ [![Minzipped size](https://badgen.net/bundlephobia/minzip/cron)](https://badgen.net/bundlephobia/minzip/cron)
16
+ [![monthly downloads](https://badgen.net/npm/dm/cron?icon=npm)](https://badgen.net/npm/dm/cron)
6
17
 
7
18
  Cron is a tool that allows you to execute _something_ on a schedule. This is
8
19
  typically done using the cron syntax. We allow you to execute a function
9
20
  whenever your scheduled job triggers. We also allow you to execute a job
10
21
  external to the javascript process using `child_process`. Additionally, this
11
- library goes beyond the basic cron syntax and allows you to
12
- supply a Date object. This will be used as the trigger for your callback. Cron
13
- syntax is still an acceptable CronTime format. Although the Cron patterns
14
- supported here extend on the standard Unix format to support seconds digits,
22
+ library goes beyond the basic cron syntax and allows you to
23
+ supply a Date object. This will be used as the trigger for your callback. Cron
24
+ syntax is still an acceptable CronTime format. Although the Cron patterns
25
+ supported here extend on the standard Unix format to support seconds digits,
15
26
  leaving it off will default to 0 and match the Unix behavior.
16
27
 
17
-
18
- Installation
19
- ==
28
+ # Installation
20
29
 
21
30
  npm install cron
22
31
 
23
-
24
- If You Are Submitting Bugs/Issues
25
- ==
32
+ # If You Are Submitting Bugs/Issues
26
33
 
27
34
  Because we can't magically know what you are doing to expose an issue, it is
28
35
  best if you provide a snippet of code. This snippet need not include your secret
29
36
  sauce, but it must replicate the issue you are describing. The issues that get
30
37
  closed without resolution tend to be the ones without code examples. Thanks.
31
38
 
32
-
33
- Versions and Backwards compatibility breaks:
34
- ==
39
+ # Versions and Backwards compatibility breaks:
35
40
 
36
41
  As goes with semver, breaking backwards compatibility should be explicit in the
37
42
  versioning of your library. As such, we'll upgrade the version of this module
@@ -39,26 +44,29 @@ in accordance with breaking changes (I'm not always great about doing it this
39
44
  way so if you notice that there are breaking changes that haven't been bumped
40
45
  appropriately please let me know).
41
46
 
42
-
43
- Usage (basic cron usage):
44
- ==
47
+ # Usage (basic cron usage):
45
48
 
46
49
  ```javascript
47
50
  var CronJob = require('cron').CronJob;
48
- new CronJob('* * * * * *', function() {
49
- console.log('You will see this message every second');
50
- }, null, true, 'America/Los_Angeles');
51
+ var job = new CronJob(
52
+ '* * * * * *',
53
+ function() {
54
+ console.log('You will see this message every second');
55
+ },
56
+ null,
57
+ true,
58
+ 'America/Los_Angeles'
59
+ );
60
+ // Use this if the 4th param is default value(false)
61
+ // job.start()
51
62
  ```
52
63
 
53
- Note - You need to explicitly start a job in order to make it run. This gives a
54
- little more control over running your jobs.
64
+ Note - You don't need to explicitly start a job in order to make it run since the 4th parameter is set to `true`. However, by default you need to call `job.start()` to start the cron job, which gives a little more control over running your jobs.
55
65
 
56
66
  There are more examples available in this repository at:
57
67
  [/examples](https://github.com/kelektiv/node-cron/tree/master/examples)
58
68
 
59
-
60
- Available Cron patterns:
61
- ==
69
+ # Available Cron patterns:
62
70
 
63
71
  Asterisk. E.g. *
64
72
  Ranges. E.g. 1-3,5
@@ -74,113 +82,102 @@ note that these don't necessarily accept the exact same syntax as this
74
82
  library, for instance, it doesn't accept the `seconds` field, so keep that in
75
83
  mind.
76
84
 
77
-
78
- Cron Ranges
79
- ==
85
+ # Cron Ranges
80
86
 
81
87
  When specifying your cron values you'll need to make sure that your values fall
82
88
  within the ranges. For instance, some cron's use a 0-7 range for the day of
83
- week where both 0 and 7 represent Sunday. We do not. And that is an optimisation.
84
-
85
- * Seconds: 0-59
86
- * Minutes: 0-59
87
- * Hours: 0-23
88
- * Day of Month: 1-31
89
- * Months: 0-11 (Jan-Dec)
90
- * Day of Week: 0-6 (Sun-Sat)
91
-
92
-
93
- Gotchas
94
- ==
95
-
96
- * Millisecond level granularity in JS or moment date objects.
97
- Because computers take time to do things, there may be some delay in execution.
98
- This should be on the order of milliseconds. This module doesn't allow MS level
99
- granularity for the regular cron syntax, but _does_ allow you to specify a real
100
- date of execution in either a javascript date object or a moment object.
101
- When this happens you may find that you aren't able to execute a job that
102
- _should_ run in the future like with `new Date().setMilliseconds(new
103
- Date().getMilliseconds() + 1)`. This is due to those cycles of execution
104
- above. This wont be the same for everyone because of compute speed. When I
105
- tried it locally I saw that somewhere around the 4-5 ms mark was where I got
106
- consistent ticks using real dates, but anything less than that would result
107
- in an exception. This could be really confusing. We could restrict the
108
- granularity for all dates to seconds, but felt that it wasn't a huge problem
109
- so long as you were made aware. If this becomes more of an issue, We can
110
- revisit it.
111
- * Arrow Functions for `onTick`
112
- Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get
113
- the `this` context of the cronjob. You can read a little more in this ticket [GH-40](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775)
114
-
115
-
116
- API
117
- ==
89
+ week where both 0 and 7 represent Sunday. We do not. And that is an optimisation.
90
+
91
+ - Seconds: 0-59
92
+ - Minutes: 0-59
93
+ - Hours: 0-23
94
+ - Day of Month: 1-31
95
+ - Months: 0-11 (Jan-Dec)
96
+ - Day of Week: 0-6 (Sun-Sat)
97
+
98
+ # Gotchas
99
+
100
+ - Millisecond level granularity in JS or moment date objects.
101
+ Because computers take time to do things, there may be some delay in execution.
102
+ This should be on the order of milliseconds. This module doesn't allow MS level
103
+ granularity for the regular cron syntax, but _does_ allow you to specify a real
104
+ date of execution in either a javascript date object or a moment object.
105
+ When this happens you may find that you aren't able to execute a job that
106
+ _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution
107
+ above. This wont be the same for everyone because of compute speed. When I
108
+ tried it locally I saw that somewhere around the 4-5 ms mark was where I got
109
+ consistent ticks using real dates, but anything less than that would result
110
+ in an exception. This could be really confusing. We could restrict the
111
+ granularity for all dates to seconds, but felt that it wasn't a huge problem
112
+ so long as you were made aware. If this becomes more of an issue, We can
113
+ revisit it.
114
+ - Arrow Functions for `onTick`
115
+ Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get
116
+ the `this` context of the cronjob. You can read a little more in this ticket [GH-40](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775)
117
+
118
+ # API
118
119
 
119
120
  Parameter Based
120
121
 
121
- * `job` - shortcut to `new cron.CronJob()`.
122
- * `time` - shortcut to `new cron.CronTime()`.
123
- * `sendAt` - tells you when a `CronTime` will be run.
124
- * `timeout` - tells you when the next timeout is.
125
- * `CronJob`
126
- * `constructor(cronTime, onTick, onComplete, start, timezone, context,
127
- runOnInit, unrefTimeout)` - Of note, the first parameter here can be a JSON object that
128
- has the below names and associated types (see examples above).
129
- * `cronTime` - [REQUIRED] - The time to fire off your job. This can be in
130
- the form of cron syntax or a JS
131
- [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
132
- * `onTick` - [REQUIRED] - The function to fire at the specified time. If an
133
- `onComplete` callback was provided, `onTick` will receive it as an argument.
134
- `onTick` may call `onComplete` when it has finished its work.
135
- * `onComplete` - [OPTIONAL] - A function that will fire when the job is
136
- stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
137
- * `start` - [OPTIONAL] - Specifies whether to start the job just before
138
- exiting the constructor. By default this is set to false. If left at default
139
- you will need to call `job.start()` in order to start the job (assuming
140
- `job` is the variable you set the cronjob to). This does not immediately
141
- fire your `onTick` function, it just gives you more control over the
142
- behavior of your jobs.
143
- * `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This
144
- will modify the actual time relative to your timezone. If the timezone is
145
- invalid, an error is thrown. You can check all timezones available at
146
- [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use
147
- both.
148
- `timeZone` and `utcOffset` together or weird things may happen.
149
- * `context` - [OPTIONAL] - The context within which to execute the onTick
150
- method. This defaults to the cronjob itself allowing you to call
151
- `this.stop()`. However, if you change this you'll have access to the
152
- functions and values within your context object.
153
- * `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick`
154
- function as soon as the requisite initialization has happened. This option
155
- is set to `false` by default for backwards compatibility.
156
- * `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your
157
- timezone rather than using the `timeZone` param. Probably don't use both
158
- `timeZone` and `utcOffset` together or weird things may happen.
159
- * `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop
160
- running and want to stop the node process when that finishes regardless of
161
- the state of your cronjob, you can do so making use of this parameter. This
162
- is off by default and cron will run as if it needs to control the event
163
- loop. For more information take a look at
164
- [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref)
165
- from the NodeJS docs.
166
- * `start` - Runs your job.
167
- * `stop` - Stops your job.
168
- * `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
169
- * `lastDate` - Tells you the last execution date.
170
- * `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
171
- * `fireOnTick` - Allows you to override the `onTick` calling behavior. This
172
- matters so only do this if you have a really good reason to do so.
173
- * `addCallback` - Allows you to add `onTick` callbacks.
174
- * `CronTime`
175
- * `constructor(time)`
176
- * `time` - [REQUIRED] - The time to fire off your job. This can be in the
177
- form of cron syntax or a JS
178
- [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date)
179
- object.
180
-
181
-
182
- Contributions
183
- ==
122
+ - `job` - shortcut to `new cron.CronJob()`.
123
+ - `time` - shortcut to `new cron.CronTime()`.
124
+ - `sendAt` - tells you when a `CronTime` will be run.
125
+ - `timeout` - tells you when the next timeout is.
126
+ - `CronJob`
127
+ - `constructor(cronTime, onTick, onComplete, start, timezone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that
128
+ has the below names and associated types (see examples above).
129
+ - `cronTime` - [REQUIRED] - The time to fire off your job. This can be in
130
+ the form of cron syntax or a JS
131
+ [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.
132
+ - `onTick` - [REQUIRED] - The function to fire at the specified time. If an
133
+ `onComplete` callback was provided, `onTick` will receive it as an argument.
134
+ `onTick` may call `onComplete` when it has finished its work.
135
+ - `onComplete` - [OPTIONAL] - A function that will fire when the job is
136
+ stopped with `job.stop()`, and may also be called by `onTick` at the end of each run.
137
+ - `start` - [OPTIONAL] - Specifies whether to start the job just before
138
+ exiting the constructor. By default this is set to false. If left at default
139
+ you will need to call `job.start()` in order to start the job (assuming
140
+ `job` is the variable you set the cronjob to). This does not immediately
141
+ fire your `onTick` function, it just gives you more control over the
142
+ behavior of your jobs.
143
+ - `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This
144
+ will modify the actual time relative to your timezone. If the timezone is
145
+ invalid, an error is thrown. You can check all timezones available at
146
+ [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use
147
+ both `timeZone` and `utcOffset` together or weird things may happen.
148
+ - `context` - [OPTIONAL] - The context within which to execute the onTick
149
+ method. This defaults to the cronjob itself allowing you to call
150
+ `this.stop()`. However, if you change this you'll have access to the
151
+ functions and values within your context object.
152
+ - `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick`
153
+ function as soon as the requisite initialization has happened. This option
154
+ is set to `false` by default for backwards compatibility.
155
+ - `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your
156
+ timezone rather than using the `timeZone` param. Probably don't use both
157
+ `timeZone` and `utcOffset` together or weird things may happen.
158
+ - `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop
159
+ running and want to stop the node process when that finishes regardless of
160
+ the state of your cronjob, you can do so making use of this parameter. This
161
+ is off by default and cron will run as if it needs to control the event
162
+ loop. For more information take a look at
163
+ [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref)
164
+ from the NodeJS docs.
165
+ - `start` - Runs your job.
166
+ - `stop` - Stops your job.
167
+ - `setTime` - Stops and changes the time for the `CronJob`. Param must be a `CronTime`.
168
+ - `lastDate` - Tells you the last execution date.
169
+ - `nextDates` - Provides an array of the next set of dates that will trigger an `onTick`.
170
+ - `fireOnTick` - Allows you to override the `onTick` calling behavior. This
171
+ matters so only do this if you have a really good reason to do so.
172
+ - `addCallback` - Allows you to add `onTick` callbacks.
173
+ - `CronTime`
174
+ - `constructor(time)`
175
+ - `time` - [REQUIRED] - The time to fire off your job. This can be in the
176
+ form of cron syntax or a JS
177
+ [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date)
178
+ object.
179
+
180
+ # Contributions
184
181
 
185
182
  This is a community effort project. In the truest sense, this project started as
186
183
  an open source project from [cron.js](http://github.com/padolsey/cron.js) and
@@ -188,8 +185,6 @@ grew into something else. Other people have contributed code, time, and
188
185
  oversight to the project. At this point there are too many to name here so I'll
189
186
  just say thanks.
190
187
 
191
-
192
- License
193
- ==
188
+ # License
194
189
 
195
190
  MIT