cron 1.1.0 → 1.3.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/.eslintrc.json +43 -0
- package/README.md +47 -7
- package/bower.json +2 -2
- package/lib/cron.js +138 -80
- package/package.json +9 -12
- package/.npmignore +0 -2
- package/lib/cron-parser.js +0 -163
- package/test.js +0 -49
- package/tests/test-cron-parser.js.bak +0 -655
- package/tests/test-cron.js +0 -518
- package/tests/test-crontime.js +0 -203
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "eslint:recommended",
|
|
3
|
+
"parserOptions": {
|
|
4
|
+
"ecmaVersion": 6,
|
|
5
|
+
"ecmaFeatures": {
|
|
6
|
+
"blockBindings": true,
|
|
7
|
+
"jsx": true,
|
|
8
|
+
"experimentalObjectRestSpread": true
|
|
9
|
+
},
|
|
10
|
+
"sourceType": "module"
|
|
11
|
+
},
|
|
12
|
+
"globals": {
|
|
13
|
+
"after": true,
|
|
14
|
+
"afterEach": true,
|
|
15
|
+
"before": true,
|
|
16
|
+
"beforeEach": true,
|
|
17
|
+
"describe": true,
|
|
18
|
+
"expect": true,
|
|
19
|
+
"it": true,
|
|
20
|
+
"ga": true
|
|
21
|
+
},
|
|
22
|
+
"env": {
|
|
23
|
+
"browser": true,
|
|
24
|
+
"node": true
|
|
25
|
+
},
|
|
26
|
+
"plugins": [
|
|
27
|
+
"react"
|
|
28
|
+
],
|
|
29
|
+
"rules": {
|
|
30
|
+
"no-console": 0,
|
|
31
|
+
"new-cap": 0,
|
|
32
|
+
"strict": 0,
|
|
33
|
+
"no-underscore-dangle": 0,
|
|
34
|
+
"no-use-before-define": 0,
|
|
35
|
+
"no-unused-vars": [2, {"args": "after-used", "argsIgnorePattern": "^_"}],
|
|
36
|
+
"eol-last": 0,
|
|
37
|
+
"quotes": [2, "single"],
|
|
38
|
+
"jsx-quotes": 1,
|
|
39
|
+
"react/jsx-no-undef": 1,
|
|
40
|
+
"react/jsx-uses-react": 1,
|
|
41
|
+
"react/jsx-uses-vars": 1
|
|
42
|
+
}
|
|
43
|
+
}
|
package/README.md
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
node-cron
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
-
[](http://travis-ci.org/#!/ncb000gt/node-cron)
|
|
5
5
|
[](https://app.wercker.com/project/bykey/0cadfe5d45ad7bc819efb636026cf230)
|
|
6
|
+
[](https://david-dm.org/ncb000gt/node-cron)
|
|
6
7
|
|
|
7
8
|
Originally this project was a NodeJS fork of [James Padolsey's][jamespadolsey] [cron.js](http://github.com/padolsey/cron.js).
|
|
8
9
|
|
|
9
10
|
After [Craig Condon][crcn] made some updates and changes to the code base this has evolved to something that has a bit of both. The cron syntax parsing is mostly James' while using timeout instead of interval is Craig's.
|
|
10
11
|
|
|
11
|
-
Additionally, this library goes beyond the basic cron syntax and allows you to supply a Date object. This will be used as the trigger for your callback. Cron syntax is still an acceptable CronTime format. Although the Cron patterns
|
|
12
|
+
Additionally, this library goes beyond the basic cron syntax and allows you to supply a Date object. This will be used as the trigger for your callback. Cron syntax is still an acceptable CronTime format. Although the Cron patterns supported here extend on the standard Unix format to support seconds digits, leaving it off will default to 0 and match the Unix behavior.
|
|
12
13
|
|
|
13
14
|
If You Are Submitting Bugs/Issues
|
|
14
15
|
=============
|
|
@@ -16,7 +17,7 @@ If You Are Submitting Bugs/Issues
|
|
|
16
17
|
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.
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
Versions and Backwards
|
|
20
|
+
Versions and Backwards compatibility breaks:
|
|
20
21
|
==========
|
|
21
22
|
|
|
22
23
|
As goes with semver, breaking backwards compatibility should be explicit in the versioning of your library. As such, we'll upgrade the version of this module in accordance with breaking changes (I'm not always great about doing it this way so if you notice that there are breaking changes that haven't been bumped appropriately please let me know). This table lists out the issues which were the reason for the break in backward compatibility.
|
|
@@ -41,6 +42,7 @@ new CronJob('* * * * * *', function() {
|
|
|
41
42
|
}, null, true, 'America/Los_Angeles');
|
|
42
43
|
```
|
|
43
44
|
|
|
45
|
+
Note - You need to explictly start a job in order to make it run. This gives a little more control over running your jobs.
|
|
44
46
|
|
|
45
47
|
Available Cron patterns:
|
|
46
48
|
==========
|
|
@@ -49,7 +51,9 @@ Available Cron patterns:
|
|
|
49
51
|
Ranges. E.g. 1-3,5
|
|
50
52
|
Steps. E.g. */2
|
|
51
53
|
|
|
52
|
-
[Read up on cron patterns here](http://crontab.org).
|
|
54
|
+
[Read up on cron patterns here](http://crontab.org). Note the examples in the
|
|
55
|
+
link have five fields, and 1 minute as the finest granularity, but this library
|
|
56
|
+
has six fields, with 1 second as the finest granularity.
|
|
53
57
|
|
|
54
58
|
Cron Ranges
|
|
55
59
|
==========
|
|
@@ -132,6 +136,40 @@ try {
|
|
|
132
136
|
```
|
|
133
137
|
|
|
134
138
|
|
|
139
|
+
How to check if a job is running
|
|
140
|
+
==========
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
var cron = require('cron');
|
|
144
|
+
|
|
145
|
+
var job1 = new cron.CronJob({
|
|
146
|
+
cronTime: '* * * * *',
|
|
147
|
+
onTick: function() {
|
|
148
|
+
console.log('job 1 ticked');
|
|
149
|
+
},
|
|
150
|
+
start: false,
|
|
151
|
+
timeZone: 'America/Los_Angeles'
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
var job2 = new cron.CronJob({
|
|
155
|
+
cronTime: '* * * * *',
|
|
156
|
+
onTick: function() {
|
|
157
|
+
console.log('job 2 ticked');
|
|
158
|
+
},
|
|
159
|
+
start: false,
|
|
160
|
+
timeZone: 'America/Los_Angeles'
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
console.log('job1 status', job1.running); // job1 status undefined
|
|
164
|
+
console.log('job2 status', job2.running); // job2 status undefined
|
|
165
|
+
|
|
166
|
+
job1.start(); // job 1 started
|
|
167
|
+
|
|
168
|
+
console.log('job1 status', job1.running); // job1 status true
|
|
169
|
+
console.log('job2 status', job2.running); // job2 status undefined
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
|
|
135
173
|
Install
|
|
136
174
|
==========
|
|
137
175
|
|
|
@@ -142,7 +180,7 @@ Install
|
|
|
142
180
|
API
|
|
143
181
|
==========
|
|
144
182
|
|
|
145
|
-
Parameter Based
|
|
183
|
+
Parameter Based
|
|
146
184
|
|
|
147
185
|
`CronJob`
|
|
148
186
|
|
|
@@ -151,9 +189,9 @@ Parameter Based
|
|
|
151
189
|
* `onTick` - [REQUIRED] - The function to fire at the specified time.
|
|
152
190
|
* `onComplete` - [OPTIONAL] - A function that will fire when the job is complete, when it is stopped.
|
|
153
191
|
* `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.
|
|
154
|
-
* `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone.
|
|
192
|
+
* `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/).
|
|
155
193
|
* `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.
|
|
156
|
-
* `runOnInit` - [OPTIONAL] - 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
|
|
194
|
+
* `runOnInit` - [OPTIONAL] - 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.
|
|
157
195
|
* `start` - Runs your job.
|
|
158
196
|
* `stop` - Stops your job.
|
|
159
197
|
|
|
@@ -173,6 +211,7 @@ Contributors
|
|
|
173
211
|
* [neyric][neyric]
|
|
174
212
|
* [humanchimp][humanchimp]
|
|
175
213
|
* [danhbear][danhbear]
|
|
214
|
+
* [Jordan Abderrachid][jordanabderrachid]
|
|
176
215
|
|
|
177
216
|
License
|
|
178
217
|
==========
|
|
@@ -188,3 +227,4 @@ MIT
|
|
|
188
227
|
[humanchimp]:http://github.com/humanchimp
|
|
189
228
|
[errorprone]:http://github.com/ErrorProne
|
|
190
229
|
[danhbear]:http://github.com/danhbear
|
|
230
|
+
[jordanabderrachid]:http://github.com/jordanabderrachid
|
package/bower.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cronjs",
|
|
3
|
-
"version": "1.0.1",
|
|
4
3
|
"homepage": "https://github.com/ncb000gt/node-cron",
|
|
5
4
|
"authors": [
|
|
6
5
|
"Romain Beauxis<toots@rastageeks.org>",
|
|
@@ -10,7 +9,8 @@
|
|
|
10
9
|
"cliftonc",
|
|
11
10
|
"neyric",
|
|
12
11
|
"humanchimp",
|
|
13
|
-
"danhbear"
|
|
12
|
+
"danhbear",
|
|
13
|
+
"Jordan Abderrachid<jabderrachid@gmail.com>"
|
|
14
14
|
],
|
|
15
15
|
"description": "js cron handler",
|
|
16
16
|
"main": ["lib/cron.js"],
|
package/lib/cron.js
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
(function (root, factory) {
|
|
2
|
+
if (typeof define === 'function' && define.amd) {
|
|
3
|
+
define(['moment-timezone'], factory);
|
|
4
|
+
} else if (typeof exports === 'object') {
|
|
5
|
+
module.exports = factory(require('moment-timezone'), require('child_process'));
|
|
6
|
+
} else {
|
|
7
|
+
root.Cron = factory(root.moment);
|
|
8
|
+
}
|
|
9
|
+
}(this, function (moment, child_process) {
|
|
10
|
+
|
|
11
|
+
var exports = {},
|
|
2
12
|
timeUnits = ['second', 'minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek'],
|
|
3
|
-
spawn =
|
|
4
|
-
moment = require('moment-timezone');
|
|
13
|
+
spawn = child_process && child_process.spawn;
|
|
5
14
|
|
|
6
|
-
function CronTime(source, zone) {
|
|
15
|
+
function CronTime(source, zone, utcOffset) {
|
|
7
16
|
this.source = source;
|
|
8
|
-
|
|
17
|
+
|
|
18
|
+
if (zone) {
|
|
19
|
+
if (moment.tz.names().indexOf(zone) === -1) {
|
|
20
|
+
throw new Error('Invalid timezone.');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.zone = zone;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (utcOffset) this.utcOffset = utcOffset;
|
|
9
27
|
|
|
10
28
|
var that = this;
|
|
11
29
|
timeUnits.map(function(timeUnit){
|
|
@@ -17,8 +35,7 @@ function CronTime(source, zone) {
|
|
|
17
35
|
this.realDate = true;
|
|
18
36
|
} else {
|
|
19
37
|
this._parse();
|
|
20
|
-
|
|
21
|
-
throw Error("Could not verify a valid date. Please verify your parameters.");
|
|
38
|
+
this._verifyParse();
|
|
22
39
|
}
|
|
23
40
|
}
|
|
24
41
|
|
|
@@ -83,23 +100,23 @@ CronTime.prototype = {
|
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
if (!ok) {
|
|
86
|
-
console.
|
|
87
|
-
return false;
|
|
103
|
+
console.warn('Month \'' + m + '\' is limited to \'' + con + '\' days.');
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
106
|
},
|
|
93
107
|
|
|
94
108
|
/**
|
|
95
109
|
* calculates the next send time
|
|
96
110
|
*/
|
|
97
|
-
sendAt: function() {
|
|
111
|
+
sendAt: function(i) {
|
|
98
112
|
var date = this.realDate ? this.source : moment();
|
|
99
113
|
// Set the timezone if given (http://momentjs.com/timezone/docs/#/using-timezones/parsing-in-zone/)
|
|
100
114
|
if (this.zone)
|
|
101
115
|
date = date.tz(this.zone);
|
|
102
116
|
|
|
117
|
+
if (this.utcOffset)
|
|
118
|
+
date = date.utcOffset(this.utcOffset);
|
|
119
|
+
|
|
103
120
|
if (this.realDate)
|
|
104
121
|
return date;
|
|
105
122
|
|
|
@@ -114,9 +131,21 @@ CronTime.prototype = {
|
|
|
114
131
|
date = date.add(1, 's');
|
|
115
132
|
}
|
|
116
133
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
134
|
+
//If the i argument is not given, return the next send time
|
|
135
|
+
if(isNaN(i) || i < 0){
|
|
136
|
+
date = this._getNextDateFrom(date);
|
|
137
|
+
return date;
|
|
138
|
+
}
|
|
139
|
+
//Else return the next i send times
|
|
140
|
+
else{
|
|
141
|
+
var dates = [];
|
|
142
|
+
for(;i>0;i--){
|
|
143
|
+
date = this._getNextDateFrom(date);
|
|
144
|
+
dates.push(moment(date));
|
|
145
|
+
if(i>1) date.add(1,'s');
|
|
146
|
+
}
|
|
147
|
+
return dates;
|
|
148
|
+
}
|
|
120
149
|
},
|
|
121
150
|
|
|
122
151
|
/**
|
|
@@ -149,15 +178,15 @@ CronTime.prototype = {
|
|
|
149
178
|
_getNextDateFrom: function(start) {
|
|
150
179
|
var date = moment(start);
|
|
151
180
|
if (date.toString() == 'Invalid date') {
|
|
152
|
-
console.log(
|
|
181
|
+
console.log('ERROR: You specified an invalid date.');
|
|
153
182
|
return date;
|
|
154
183
|
}
|
|
155
184
|
if (this.realDate && start < new Date())
|
|
156
|
-
console.log(
|
|
185
|
+
console.log('WARNING: Date in past. Will never be fired.');
|
|
157
186
|
if (this.realDate) return date;
|
|
158
187
|
|
|
159
188
|
//sanity check
|
|
160
|
-
while (
|
|
189
|
+
while (true) {
|
|
161
190
|
var diff = date - start,
|
|
162
191
|
origDate = new Date(date);
|
|
163
192
|
|
|
@@ -229,8 +258,7 @@ CronTime.prototype = {
|
|
|
229
258
|
* get next date that is a valid DST date
|
|
230
259
|
*/
|
|
231
260
|
_findDST: function(date) {
|
|
232
|
-
var newDate = moment(date)
|
|
233
|
-
addSeconds = 1;
|
|
261
|
+
var newDate = moment(date);
|
|
234
262
|
while (newDate <= date)
|
|
235
263
|
newDate.add(1, 's');
|
|
236
264
|
|
|
@@ -287,55 +315,56 @@ CronTime.prototype = {
|
|
|
287
315
|
},
|
|
288
316
|
|
|
289
317
|
_parseField: function(field, type, constraints) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
318
|
+
var rangePattern = /^(\d+)(?:-(\d+))?(?:\/(\d+))?$/g,
|
|
319
|
+
typeObj = this[type],
|
|
320
|
+
pointer,
|
|
321
|
+
low = constraints[0],
|
|
322
|
+
high = constraints[1];
|
|
323
|
+
|
|
324
|
+
// * is a shortcut to [lower-upper] range
|
|
325
|
+
field = field.replace(/\*/g, low + '-' + high);
|
|
326
|
+
|
|
327
|
+
//commas separate information, so split based on those
|
|
328
|
+
var allRanges = field.split(',');
|
|
329
|
+
|
|
330
|
+
for (var i = 0; i < allRanges.length; i++) {
|
|
331
|
+
if (allRanges[i].match(rangePattern)) {
|
|
332
|
+
allRanges[i].replace(rangePattern, function($0, lower, upper, step) {
|
|
333
|
+
step = parseInt(step) || 1;
|
|
334
|
+
// Positive integer higher than constraints[0]
|
|
335
|
+
lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
|
|
336
|
+
|
|
337
|
+
// Positive integer lower than constraints[1]
|
|
338
|
+
upper = upper ? Math.min(high, ~~Math.abs(upper)) : lower;
|
|
339
|
+
|
|
340
|
+
// Count from the lower barrier to the upper
|
|
341
|
+
pointer = lower;
|
|
342
|
+
|
|
343
|
+
do {
|
|
344
|
+
typeObj[pointer] = true
|
|
345
|
+
pointer += step;
|
|
346
|
+
} while (pointer <= upper);
|
|
347
|
+
});
|
|
348
|
+
} else {
|
|
349
|
+
throw new Error('Field (' + field + ') cannot be parsed');
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
325
353
|
};
|
|
326
354
|
|
|
327
355
|
function command2function(cmd) {
|
|
356
|
+
var command, args;
|
|
328
357
|
switch (typeof cmd) {
|
|
329
358
|
case 'string':
|
|
330
|
-
|
|
331
|
-
|
|
359
|
+
args = cmd.split(' ');
|
|
360
|
+
command = args.shift();
|
|
332
361
|
|
|
333
362
|
cmd = spawn.bind(undefined, command, args);
|
|
334
363
|
break;
|
|
335
364
|
case 'object':
|
|
336
|
-
|
|
365
|
+
command = cmd && cmd.command;
|
|
337
366
|
if (command) {
|
|
338
|
-
|
|
367
|
+
args = cmd.args;
|
|
339
368
|
var options = cmd.options;
|
|
340
369
|
|
|
341
370
|
cmd = spawn.bind(undefined, command, args, options);
|
|
@@ -346,9 +375,9 @@ function command2function(cmd) {
|
|
|
346
375
|
return cmd
|
|
347
376
|
}
|
|
348
377
|
|
|
349
|
-
function CronJob(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit) {
|
|
378
|
+
function CronJob(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit, utcOffset) {
|
|
350
379
|
var _cronTime = cronTime;
|
|
351
|
-
if (typeof cronTime !=
|
|
380
|
+
if (typeof cronTime != 'string' && arguments.length == 1) {
|
|
352
381
|
//crontime is an object...
|
|
353
382
|
onTick = cronTime.onTick;
|
|
354
383
|
onComplete = cronTime.onComplete;
|
|
@@ -357,12 +386,13 @@ function CronJob(cronTime, onTick, onComplete, startNow, timeZone, context, runO
|
|
|
357
386
|
timeZone = cronTime.timeZone;
|
|
358
387
|
runOnInit = cronTime.runOnInit;
|
|
359
388
|
_cronTime = cronTime.cronTime;
|
|
389
|
+
utcOffset = cronTime.utcOffset;
|
|
360
390
|
}
|
|
361
391
|
|
|
362
392
|
this.context = (context || this);
|
|
363
393
|
this._callbacks = [];
|
|
364
394
|
this.onComplete = command2function(onComplete);
|
|
365
|
-
this.cronTime = new CronTime(_cronTime, timeZone);
|
|
395
|
+
this.cronTime = new CronTime(_cronTime, timeZone, utcOffset);
|
|
366
396
|
|
|
367
397
|
addCallback.call(this, command2function(onTick));
|
|
368
398
|
|
|
@@ -393,6 +423,10 @@ var fireOnTick = function() {
|
|
|
393
423
|
}
|
|
394
424
|
CronJob.prototype.fireOnTick = fireOnTick;
|
|
395
425
|
|
|
426
|
+
CronJob.prototype.nextDates = function(i) {
|
|
427
|
+
return this.cronTime.sendAt(i);
|
|
428
|
+
}
|
|
429
|
+
|
|
396
430
|
var start = function() {
|
|
397
431
|
if (this.running) return;
|
|
398
432
|
|
|
@@ -400,19 +434,37 @@ var start = function() {
|
|
|
400
434
|
var self = this;
|
|
401
435
|
var timeout = this.cronTime.getTimeout();
|
|
402
436
|
var remaining = 0;
|
|
437
|
+
var startTime;
|
|
403
438
|
|
|
404
439
|
if (this.cronTime.realDate) this.runOnce = true;
|
|
405
440
|
|
|
441
|
+
function _setTimeout(timeout) {
|
|
442
|
+
startTime = Date.now();
|
|
443
|
+
self._timeout = setTimeout(callbackWrapper, timeout);
|
|
444
|
+
}
|
|
445
|
+
|
|
406
446
|
// The callback wrapper checks if it needs to sleep another period or not
|
|
407
447
|
// and does the real callback logic when it's time.
|
|
408
448
|
|
|
409
449
|
function callbackWrapper() {
|
|
450
|
+
var diff = startTime + timeout - Date.now();
|
|
451
|
+
|
|
452
|
+
if (diff > 0) {
|
|
453
|
+
var newTimeout = self.cronTime.getTimeout();
|
|
454
|
+
|
|
455
|
+
if (newTimeout > diff) {
|
|
456
|
+
newTimeout = diff;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
remaining += newTimeout;
|
|
460
|
+
}
|
|
410
461
|
|
|
411
462
|
// If there is sleep time remaining, calculate how long and go to sleep
|
|
412
463
|
// again. This processing might make us miss the deadline by a few ms
|
|
413
464
|
// times the number of sleep sessions. Given a MAXDELAY of almost a
|
|
414
465
|
// month, this should be no issue.
|
|
415
466
|
|
|
467
|
+
self.lastExecution = new Date();
|
|
416
468
|
if (remaining) {
|
|
417
469
|
if (remaining > MAXDELAY) {
|
|
418
470
|
remaining -= MAXDELAY;
|
|
@@ -422,7 +474,7 @@ var start = function() {
|
|
|
422
474
|
remaining = 0;
|
|
423
475
|
}
|
|
424
476
|
|
|
425
|
-
|
|
477
|
+
_setTimeout(timeout);
|
|
426
478
|
} else {
|
|
427
479
|
|
|
428
480
|
// We have arrived at the correct point in time.
|
|
@@ -448,7 +500,7 @@ var start = function() {
|
|
|
448
500
|
timeout = MAXDELAY;
|
|
449
501
|
}
|
|
450
502
|
|
|
451
|
-
|
|
503
|
+
_setTimeout(timeout);
|
|
452
504
|
} else {
|
|
453
505
|
this.stop();
|
|
454
506
|
}
|
|
@@ -456,6 +508,10 @@ var start = function() {
|
|
|
456
508
|
|
|
457
509
|
CronJob.prototype.start = start;
|
|
458
510
|
|
|
511
|
+
CronJob.prototype.lastDate = function(){
|
|
512
|
+
return this.lastExecution;
|
|
513
|
+
};
|
|
514
|
+
|
|
459
515
|
/**
|
|
460
516
|
* Stop the cronjob.
|
|
461
517
|
*/
|
|
@@ -466,23 +522,25 @@ CronJob.prototype.stop = function() {
|
|
|
466
522
|
if (typeof this.onComplete == 'function') this.onComplete();
|
|
467
523
|
}
|
|
468
524
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
exports.time = function(cronTime, timeZone) {
|
|
475
|
-
return new CronTime(cronTime, timeZone);
|
|
476
|
-
}
|
|
525
|
+
exports.job = function(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit) {
|
|
526
|
+
return new CronJob(cronTime, onTick, onComplete, startNow, timeZone, context, runOnInit);
|
|
527
|
+
}
|
|
477
528
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
529
|
+
exports.time = function(cronTime, timeZone) {
|
|
530
|
+
return new CronTime(cronTime, timeZone);
|
|
531
|
+
}
|
|
481
532
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
533
|
+
exports.sendAt = function(cronTime) {
|
|
534
|
+
return exports.time(cronTime).sendAt();
|
|
535
|
+
}
|
|
485
536
|
|
|
486
|
-
|
|
487
|
-
exports.
|
|
537
|
+
exports.timeout = function(cronTime) {
|
|
538
|
+
return exports.time(cronTime).getTimeout();
|
|
488
539
|
}
|
|
540
|
+
|
|
541
|
+
exports.CronJob = CronJob;
|
|
542
|
+
exports.CronTime = CronTime;
|
|
543
|
+
|
|
544
|
+
return exports;
|
|
545
|
+
|
|
546
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cron",
|
|
3
3
|
"description": "Cron jobs for your node",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)",
|
|
6
|
-
"bugs"
|
|
7
|
-
"url"
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "http://github.com/kelektiv/node-cron/issues"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "http://github.com/
|
|
11
|
+
"url": "http://github.com/kelektiv/node-cron.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "lib/cron",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"test": "make test"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"moment-timezone": "
|
|
18
|
+
"moment-timezone": "^0.5.x"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"mocha": "~2.3.3",
|
|
22
22
|
"chai": "~3.4.0",
|
|
23
23
|
"sinon": "~1.12.x"
|
|
24
24
|
},
|
|
25
|
-
"
|
|
26
|
-
{
|
|
27
|
-
"type": "MIT",
|
|
28
|
-
"url": "http://www.opensource.org/licenses/mit-license.php"
|
|
29
|
-
}
|
|
30
|
-
],
|
|
25
|
+
"license": "MIT",
|
|
31
26
|
"contributors": [
|
|
32
27
|
"Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)",
|
|
33
28
|
"James Padolsey <> (https://github.com/jamespadolsey)",
|
|
@@ -39,6 +34,8 @@
|
|
|
39
34
|
"Dan Bear <daniel@hulu.com> (https://github.com/danhbear)",
|
|
40
35
|
"Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)",
|
|
41
36
|
"Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)",
|
|
42
|
-
"Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)"
|
|
37
|
+
"Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)",
|
|
38
|
+
"Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)",
|
|
39
|
+
"Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)"
|
|
43
40
|
]
|
|
44
41
|
}
|
package/.npmignore
DELETED