cron 2.3.0 → 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.
@@ -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;
package/.editorconfig DELETED
@@ -1,5 +0,0 @@
1
- root = true
2
-
3
- [*.{js}]
4
- indent_style = tab
5
- indent_size = 2
package/.eslintrc DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "extends": ["standard", "prettier", "prettier/standard"],
3
- "parserOptions": {
4
- "ecmaVersion": 2018
5
- },
6
- "globals": {
7
- "define": "readonly"
8
- },
9
- "env": {
10
- "browser": true,
11
- "es6": true,
12
- "node": true,
13
- "jest/globals": true
14
- },
15
- "plugins": ["prettier", "standard", "jest"],
16
- "rules": {
17
- "space-before-function-paren": 0,
18
- "new-cap": 0,
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
25
- }
26
- }
@@ -1,26 +0,0 @@
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
-
@@ -1,31 +0,0 @@
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
-
@@ -1,39 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "arrowParens": "avoid",
3
- "endOfLine": "auto",
4
- "singleQuote": true,
5
- "trailingComma": "none",
6
- "useTabs": true
7
- }
package/bower.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "name": "cronjs",
3
- "homepage": "https://github.com/ncb000gt/node-cron",
4
- "authors": [
5
- "Romain Beauxis<toots@rastageeks.org>",
6
- "James Padoulsey<@padolsey>",
7
- "Craig Condon<craig@browsertap.com>",
8
- "Finn Herpich",
9
- "cliftonc",
10
- "neyric",
11
- "humanchimp",
12
- "danhbear",
13
- "Jordan Abderrachid<jabderrachid@gmail.com>"
14
- ],
15
- "description": "js cron handler",
16
- "main": ["lib/cron.js"],
17
- "keywords": [
18
- "cron",
19
- "js"
20
- ],
21
- "license": "MIT",
22
- "ignore": [
23
- "**/.*",
24
- "node_modules",
25
- "bower_components",
26
- "test",
27
- "tests"
28
- ]
29
- }
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('* 10 * * * *', function() {
5
- const d = new Date();
6
- console.log('At Ten Minutes:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('00 00 00 * * *', function() {
5
- const d = new Date();
6
- console.log('Midnight:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
package/examples/basic.js DELETED
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('* * * * * *', function() {
5
- const d = new Date();
6
- console.log('Every second:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('* 4-22 * * 1-5', function() {
5
- const d = new Date();
6
- console.log('Every Minute Between hours 4-22, Monday through Friday:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('0 */10 * * * *', function() {
5
- const d = new Date();
6
- console.log('Every Tenth Minute:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('0 */30 9-17 * * *', function() {
5
- const d = new Date();
6
- console.log('Every 30 minutes between 9-17:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
@@ -1,24 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- const job = new CronJob(
4
- '0 * * * * *',
5
- function() {
6
- console.log('Date: ', new Date());
7
- },
8
- null,
9
- true
10
- );
11
-
12
- console.log('System TZ next 5: ', job.nextDates(5));
13
-
14
- const jobUTC = new CronJob(
15
- '0 * * * * *',
16
- function() {
17
- console.log('Date: ', new Date());
18
- },
19
- null,
20
- true,
21
- 'UTC'
22
- );
23
-
24
- console.log('UTC next 5: ', jobUTC.nextDates(5));
@@ -1,19 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- // XXX: SEE README GOTCHAS ABOUT WHY THIS COULD BE IN THE PAST!
4
- let d = new Date();
5
- d.setMilliseconds(d.getMilliseconds() + 1);
6
-
7
- console.log('Before job instantiation');
8
- const job = new CronJob(
9
- d,
10
- () => {
11
- const d2 = new Date();
12
- console.log('Tick @:', d2);
13
- },
14
- () => {
15
- console.log('complete');
16
- }
17
- );
18
- console.log('After job instantiation');
19
- job.start();
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- try {
4
- new CronJob('NOT VALID', () => {
5
- console.log('shouldn\'t get printed');
6
- });
7
- } catch(e) {
8
- console.log('omg err', e);
9
- }
@@ -1,10 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('* * * * * *', function() {
5
- const d = new Date();
6
- console.log('Every second:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
10
- console.log('is job running? ', job.running);
@@ -1,20 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- let isRunning = false;
4
- console.log('Before job instantiation');
5
- const job = new CronJob('* * * * * *', function() {
6
- const d = new Date();
7
- console.log('Check every second:', d, ', isRunning: ', isRunning);
8
-
9
- if (!isRunning) {
10
- isRunning = true;
11
-
12
- setTimeout(function() {
13
- console.log('Long running onTick complete:', new Date());
14
- isRunning = false;
15
- }, 3000);
16
- console.log('setTimeout triggered:', new Date());
17
- }
18
- });
19
- console.log('After job instantiation');
20
- job.start();
@@ -1,9 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('00 30 11 * * 1-5', function() {
5
- const d = new Date();
6
- console.log('onTick:', d);
7
- });
8
- console.log('After job instantiation');
9
- job.start();
@@ -1,15 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- const job = new CronJob('*/5 * * * * *', function() {
5
- const d = new Date();
6
- console.log('First:', d);
7
- });
8
-
9
- const job2 = new CronJob('*/8 * * * * *', function() {
10
- const d = new Date();
11
- console.log('Second:', d);
12
- });
13
- console.log('After job instantiation');
14
- job.start();
15
- job2.start();
@@ -1,23 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- let isRunning = false;
4
- console.log('Before job instantiation');
5
- const job = new CronJob({
6
- cronTime: '* * * * * *',
7
- onTick: function() {
8
- const d = new Date();
9
- console.log('Check every second:', d, ', isRunning: ', isRunning);
10
-
11
- if (!isRunning) {
12
- isRunning = true;
13
-
14
- setTimeout(function() {
15
- console.log('Long running onTick complete:', new Date());
16
- isRunning = false;
17
- }, 3000);
18
- console.log('setTimeout triggered:', new Date());
19
- }
20
- }
21
- });
22
- console.log('After job instantiation');
23
- job.start();
@@ -1,11 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('Before job instantiation');
4
- let date = new Date();
5
- date.setSeconds(date.getSeconds()+2);
6
- const job = new CronJob(date, function() {
7
- const d = new Date();
8
- console.log('Specific date:', date, ', onTick at:', d);
9
- });
10
- console.log('After job instantiation');
11
- job.start();
@@ -1,13 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('first');
4
- const job = new CronJob(
5
- '0 0 9 4 * *',
6
- function() {
7
- console.log('message');
8
- },
9
- null,
10
- true,
11
- 'America/Sao_Paulo'
12
- );
13
- console.log('second');
@@ -1,16 +0,0 @@
1
- const CronJob = require('../lib/cron.js').CronJob;
2
-
3
- console.log('first');
4
- const job = new CronJob(
5
- '0 0 9 4 * *',
6
- function() {
7
- console.log('message');
8
- },
9
- null,
10
- true,
11
- null,
12
- null,
13
- null,
14
- -360, // UTC-6, represented in minutes
15
- );
16
- console.log('second');