node-schedule 1.2.3 → 1.2.4

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 CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "env": {
3
- "node": true
3
+ "node": true,
4
+ "es6": true
4
5
  },
5
6
  "rules": {
6
- "eqeqeq": [2, "smart"],
7
- "indent": [2, 2],
8
- "no-constant-condition": false,
9
- "no-redeclare": 1,
10
- "no-underscore-dangle": false,
11
- "no-use-before-define": [true,"nofunc"],
12
- "quotes": [2, "single"],
13
- "space-before-blocks": 2,
14
- "strict": 2
7
+ "eqeqeq": ["error", "smart"],
8
+ "indent": ["error", 2, { "SwitchCase": 1 }],
9
+ "no-constant-condition": "off",
10
+ "no-redeclare": "warn",
11
+ "no-underscore-dangle": "off",
12
+ "no-use-before-define": ["warn","nofunc"],
13
+ "quotes": ["error", "single"],
14
+ "space-before-blocks": "error",
15
+ "strict": "error"
15
16
  }
16
17
  }
package/.travis.yml CHANGED
@@ -5,5 +5,11 @@ node_js:
5
5
  - "4"
6
6
  - "6"
7
7
  - "7"
8
- before_script: npm run lint
8
+ before_script: >
9
+ if nvm ls-remote --lts | grep "$(nvm current)"; then
10
+ echo "running on a LTS node version, linting"
11
+ npm test
12
+ else
13
+ echo "running on a non-LTS node version, skipping linting"
14
+ fi
9
15
  script: ./node_modules/.bin/istanbul cover ./node_modules/.bin/nodeunit test && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage
package/README.md CHANGED
@@ -48,8 +48,9 @@ They also emit a `scheduled` event each time they're scheduled to run, and a
48
48
  `canceled` event when an invocation is canceled before it's executed (both events
49
49
  receive a JavaScript date object as a parameter). Note that jobs are scheduled the
50
50
  first time immediately, so if you create a job using the `scheduleJob()`
51
- convenience method, you'll miss the first `scheduled` event. Also note that
52
- `canceled` is the single-L American spelling.
51
+ convenience method, you'll miss the first `scheduled` event, but you can query the
52
+ invocation manually (see below). Also note that `canceled` is the single-L American
53
+ spelling.
53
54
 
54
55
  ### Cron-style Scheduling
55
56
 
@@ -110,12 +111,6 @@ var j = schedule.scheduleJob(date, function(){
110
111
  });
111
112
  ```
112
113
 
113
- You can invalidate the job with the `cancel()` method:
114
-
115
- ```js
116
- j.cancel();
117
- ```
118
-
119
114
  To use current data in the future you can use binding:
120
115
 
121
116
  ```js
@@ -200,6 +195,32 @@ var j = schedule.scheduleJob({ start: startTime, end: endTime, rule: '*/1 * * *
200
195
  });
201
196
  ```
202
197
 
198
+ ### Handle Jobs and Job Invocations
199
+
200
+ There are some function to get informations for a Job and to handle the Job and
201
+ Invocations.
202
+
203
+
204
+ #### job.cancel(reshedule)
205
+ You can invalidate any job with the `cancel()` method:
206
+
207
+ ```js
208
+ j.cancel();
209
+ ```
210
+ All planned invocations will be canceled. When you set the parameter ***reschedule***
211
+ to true then the Job is newly scheduled afterwards.
212
+
213
+ #### job.cancelNext(reshedule)
214
+ This method invalidates the next planned invocation or the job.
215
+ When you set the parameter ***reschedule*** to true then the Job is newly scheduled
216
+ afterwards.
217
+
218
+ #### job.reschedule(spec)
219
+ This method cancels all pending invocation and registers the Job completely new again using the given specification.
220
+ Return true/false on success/failure.
221
+
222
+ #### job.nextInvocation()
223
+ This method returns a Date object for the planned next Invocation for this Job. If no invocation is planned the method returns null.
203
224
 
204
225
  ## Contributing
205
226
 
package/lib/schedule.js CHANGED
@@ -15,6 +15,7 @@ var events = require('events'),
15
15
 
16
16
  /* Job object */
17
17
  var anonJobCounter = 0;
18
+ var scheduledJobs = {};
18
19
 
19
20
  function isValidDate(date) {
20
21
  // Taken from http://stackoverflow.com/a/12372720/1562178
@@ -190,8 +191,8 @@ Job.prototype.schedule = function(spec) {
190
191
  if (typeof spec === 'object' && spec.rule) {
191
192
  start = spec.start || undefined;
192
193
  end = spec.end || undefined;
193
- spec = spec.rule;
194
194
  tz = spec.tz;
195
+ spec = spec.rule;
195
196
 
196
197
  if (start) {
197
198
  if (!(start instanceof Date)) {
@@ -589,8 +590,6 @@ function scheduleNextRecurrence(rule, job, prevDate, endDate) {
589
590
  }
590
591
 
591
592
  /* Convenience methods */
592
- var scheduledJobs = {};
593
-
594
593
  function scheduleJob() {
595
594
  if (arguments.length < 2) {
596
595
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-schedule",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "A cron-like and not-cron-like job scheduler for Node.",
5
5
  "keywords": [
6
6
  "schedule",
@@ -12,7 +12,7 @@
12
12
  "main": "./lib/schedule.js",
13
13
  "scripts": {
14
14
  "test": "nodeunit",
15
- "lint": "eslint lib"
15
+ "lint": "eslint lib test"
16
16
  },
17
17
  "author": {
18
18
  "name": "Matt Patenaude",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "coveralls": "^2.11.2",
33
- "eslint": "^0.15.1",
33
+ "eslint": "^3.19.0",
34
34
  "istanbul": "^0.4.5",
35
35
  "nodeunit": "^0.10.2",
36
36
  "sinon": "^1.14.1"
package/test/.eslintrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "rules": {
3
+ "quotes": ["off"]
4
+ }
5
+ }
@@ -37,32 +37,32 @@ module.exports = {
37
37
  clock.tick(3250);
38
38
  },
39
39
  "Job doesn't emit initial 'scheduled' event": function(test) {
40
- var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {});
40
+ var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {});
41
41
 
42
- job.on('scheduled', function() {
43
- test.ok(false);
44
- });
42
+ job.on('scheduled', function() {
43
+ test.ok(false);
44
+ });
45
45
 
46
- setTimeout(function() {
47
- test.done();
48
- }, 1250);
46
+ setTimeout(function() {
47
+ test.done();
48
+ }, 1250);
49
49
 
50
- clock.tick(1250);
51
- },
52
- "Won't run job if scheduled in the past": function(test) {
53
- test.expect(1);
54
- var job = schedule.scheduleJob(new Date(Date.now() - 3000), function() {
55
- test.ok(false);
56
- });
50
+ clock.tick(1250);
51
+ },
52
+ "Won't run job if scheduled in the past": function(test) {
53
+ test.expect(1);
54
+ var job = schedule.scheduleJob(new Date(Date.now() - 3000), function() {
55
+ test.ok(false);
56
+ });
57
57
 
58
- test.equal(job, null);
58
+ test.equal(job, null);
59
59
 
60
- setTimeout(function() {
61
- test.done();
62
- }, 1000);
60
+ setTimeout(function() {
61
+ test.done();
62
+ }, 1000);
63
63
 
64
- clock.tick(1000);
65
- }
64
+ clock.tick(1000);
65
+ }
66
66
  },
67
67
  ".scheduleJob(RecurrenceRule, fn)": {
68
68
  "Runs job at interval based on recur rule, repeating indefinitely": function(test) {
@@ -83,44 +83,44 @@ module.exports = {
83
83
  clock.tick(3250);
84
84
  },
85
85
  "Job doesn't emit initial 'scheduled' event": function(test) {
86
- /*
87
- * If this was Job#schedule it'd fire 4 times.
88
- */
89
- test.expect(3);
86
+ /*
87
+ * If this was Job#schedule it'd fire 4 times.
88
+ */
89
+ test.expect(3);
90
90
 
91
- var rule = new schedule.RecurrenceRule();
92
- rule.second = null; // fire every second
91
+ var rule = new schedule.RecurrenceRule();
92
+ rule.second = null; // fire every second
93
93
 
94
- var job = new schedule.scheduleJob(rule, function() {});
94
+ var job = new schedule.scheduleJob(rule, function() {});
95
95
 
96
- job.on('scheduled', function(runOnDate) {
97
- test.ok(true);
98
- });
96
+ job.on('scheduled', function(runOnDate) {
97
+ test.ok(true);
98
+ });
99
99
 
100
- setTimeout(function() {
101
- job.cancel();
102
- test.done();
103
- }, 3250);
100
+ setTimeout(function() {
101
+ job.cancel();
102
+ test.done();
103
+ }, 3250);
104
104
 
105
- clock.tick(3250);
106
- },
107
- "Doesn't invoke job if recur rule schedules it in the past": function(test) {
108
- test.expect(1);
109
- var rule = new schedule.RecurrenceRule();
110
- rule.year = 1960;
105
+ clock.tick(3250);
106
+ },
107
+ "Doesn't invoke job if recur rule schedules it in the past": function(test) {
108
+ test.expect(1);
109
+ var rule = new schedule.RecurrenceRule();
110
+ rule.year = 1960;
111
111
 
112
- var job = schedule.scheduleJob(rule, function() {
113
- test.ok(false);
114
- });
115
-
116
- test.equal(job, null);
112
+ var job = schedule.scheduleJob(rule, function() {
113
+ test.ok(false);
114
+ });
115
+
116
+ test.equal(job, null);
117
117
 
118
- setTimeout(function() {
119
- test.done();
120
- }, 1000);
118
+ setTimeout(function() {
119
+ test.done();
120
+ }, 1000);
121
121
 
122
- clock.tick(1000);
123
- }
122
+ clock.tick(1000);
123
+ }
124
124
  },
125
125
  ".scheduleJob({...}, fn)": {
126
126
  "Runs job at interval based on object, repeating indefinitely": function(test) {
@@ -140,46 +140,46 @@ module.exports = {
140
140
  clock.tick(3250);
141
141
  },
142
142
  "Job doesn't emit initial 'scheduled' event": function(test) {
143
- /*
144
- * With Job#schedule this would be 3:
145
- * scheduled at time 0
146
- * scheduled at time 1000
147
- * scheduled at time 2000
148
- */
149
- test.expect(2);
150
-
151
- var job = schedule.scheduleJob({
152
- second: null // fire every second
153
- }, function() {});
154
-
155
- job.on('scheduled', function() {
156
- test.ok(true);
157
- });
143
+ /*
144
+ * With Job#schedule this would be 3:
145
+ * scheduled at time 0
146
+ * scheduled at time 1000
147
+ * scheduled at time 2000
148
+ */
149
+ test.expect(2);
158
150
 
159
- setTimeout(function() {
160
- job.cancel();
161
- test.done();
162
- }, 2250);
151
+ var job = schedule.scheduleJob({
152
+ second: null // fire every second
153
+ }, function() {});
163
154
 
164
- clock.tick(2250);
165
- },
166
- "Doesn't invoke job if object schedules it in the past": function(test) {
167
- test.expect(1);
155
+ job.on('scheduled', function() {
156
+ test.ok(true);
157
+ });
158
+
159
+ setTimeout(function() {
160
+ job.cancel();
161
+ test.done();
162
+ }, 2250);
163
+
164
+ clock.tick(2250);
165
+ },
166
+ "Doesn't invoke job if object schedules it in the past": function(test) {
167
+ test.expect(1);
168
+
169
+ var job = schedule.scheduleJob({
170
+ year: 1960
171
+ }, function() {
172
+ test.ok(false);
173
+ });
168
174
 
169
- var job = schedule.scheduleJob({
170
- year: 1960
171
- }, function() {
172
- test.ok(false);
173
- });
174
-
175
- test.equal(job, null);
175
+ test.equal(job, null);
176
176
 
177
- setTimeout(function() {
178
- test.done();
179
- }, 1000);
177
+ setTimeout(function() {
178
+ test.done();
179
+ }, 1000);
180
180
 
181
- clock.tick(1000);
182
- }
181
+ clock.tick(1000);
182
+ }
183
183
  },
184
184
  ".scheduleJob({...}, {...}, fn)": {
185
185
  "Callback called for each job if callback is provided": function(test) {
@@ -38,7 +38,7 @@ module.exports = {
38
38
  }
39
39
  },
40
40
  "UTC": {
41
- "Should accept a valid UTC date in milliseconds": function(test) {
41
+ "Should accept a valid UTC date in milliseconds": function(test) {
42
42
  test.expect(1);
43
43
 
44
44
  schedule.scheduleJob(new Date(Date.now() + 1000).getTime(), function() {
package/test/job-test.js CHANGED
@@ -199,47 +199,47 @@ module.exports = {
199
199
  clock.tick(3250);
200
200
  },
201
201
  "Job emits 'scheduled' event for every next invocation": function(test) {
202
- // Job will run 3 times but be scheduled 4 times, 4th run never happens
203
- // due to cancel.
204
- test.expect(4);
202
+ // Job will run 3 times but be scheduled 4 times, 4th run never happens
203
+ // due to cancel.
204
+ test.expect(4);
205
205
 
206
- var job = new schedule.Job(function() {});
206
+ var job = new schedule.Job(function() {});
207
207
 
208
- job.on('scheduled', function(runOnDate) {
209
- test.ok(true);
210
- });
208
+ job.on('scheduled', function(runOnDate) {
209
+ test.ok(true);
210
+ });
211
211
 
212
- var rule = new schedule.RecurrenceRule();
213
- rule.second = null; // fire every second
212
+ var rule = new schedule.RecurrenceRule();
213
+ rule.second = null; // fire every second
214
214
 
215
- job.schedule(rule);
215
+ job.schedule(rule);
216
216
 
217
- setTimeout(function() {
218
- job.cancel();
219
- test.done();
220
- }, 3250);
217
+ setTimeout(function() {
218
+ job.cancel();
219
+ test.done();
220
+ }, 3250);
221
221
 
222
- clock.tick(3250);
223
- },
224
- "Doesn't invoke job if recur rule schedules it in the past": function(test) {
225
- test.expect(0);
222
+ clock.tick(3250);
223
+ },
224
+ "Doesn't invoke job if recur rule schedules it in the past": function(test) {
225
+ test.expect(0);
226
226
 
227
- var job = new schedule.Job(function() {
228
- test.ok(false);
229
- });
227
+ var job = new schedule.Job(function() {
228
+ test.ok(false);
229
+ });
230
230
 
231
- var rule = new schedule.RecurrenceRule();
232
- rule.year = 2000;
231
+ var rule = new schedule.RecurrenceRule();
232
+ rule.year = 2000;
233
233
 
234
- job.schedule(rule);
234
+ job.schedule(rule);
235
235
 
236
- setTimeout(function() {
237
- job.cancel();
238
- test.done();
239
- }, 1000);
236
+ setTimeout(function() {
237
+ job.cancel();
238
+ test.done();
239
+ }, 1000);
240
240
 
241
- clock.tick(1000);
242
- }
241
+ clock.tick(1000);
242
+ }
243
243
  },
244
244
  "#schedule({...})": {
245
245
  "Runs job at interval based on object, repeating indefinitely": function(test) {
@@ -261,45 +261,45 @@ module.exports = {
261
261
  clock.tick(3250);
262
262
  },
263
263
  "Job emits 'scheduled' event for every next invocation": function(test) {
264
- // Job will run 3 times but be scheduled 4 times, 4th run never happens
265
- // due to cancel.
266
- test.expect(4);
264
+ // Job will run 3 times but be scheduled 4 times, 4th run never happens
265
+ // due to cancel.
266
+ test.expect(4);
267
267
 
268
- var job = new schedule.Job(function() {});
268
+ var job = new schedule.Job(function() {});
269
269
 
270
- job.on('scheduled', function(runOnDate) {
271
- test.ok(true);
272
- });
270
+ job.on('scheduled', function(runOnDate) {
271
+ test.ok(true);
272
+ });
273
273
 
274
- job.schedule({
275
- second: null // Fire every second
276
- });
274
+ job.schedule({
275
+ second: null // Fire every second
276
+ });
277
277
 
278
- setTimeout(function() {
279
- job.cancel();
280
- test.done();
281
- }, 3250);
278
+ setTimeout(function() {
279
+ job.cancel();
280
+ test.done();
281
+ }, 3250);
282
282
 
283
- clock.tick(3250);
284
- },
285
- "Doesn't invoke job if object schedules it in the past": function(test) {
286
- test.expect(0);
283
+ clock.tick(3250);
284
+ },
285
+ "Doesn't invoke job if object schedules it in the past": function(test) {
286
+ test.expect(0);
287
287
 
288
- var job = new schedule.Job(function() {
289
- test.ok(false);
290
- });
288
+ var job = new schedule.Job(function() {
289
+ test.ok(false);
290
+ });
291
291
 
292
- job.schedule({
293
- year: 2000
294
- });
292
+ job.schedule({
293
+ year: 2000
294
+ });
295
295
 
296
- setTimeout(function() {
297
- job.cancel();
298
- test.done();
299
- }, 1000);
296
+ setTimeout(function() {
297
+ job.cancel();
298
+ test.done();
299
+ }, 1000);
300
300
 
301
- clock.tick(1000);
302
- }
301
+ clock.tick(1000);
302
+ }
303
303
  },
304
304
  "#schedule('jobName', {...})": {
305
305
  "Runs job with a custom name input": function(test) {
@@ -302,72 +302,72 @@ module.exports = {
302
302
  "nextInvocationDate on an invalid month should return null": function(test) {
303
303
  var rule = new schedule.RecurrenceRule();
304
304
  rule.month = 12;
305
- var next = rule.nextInvocationDate(next);
305
+ var next = rule.nextInvocationDate();
306
306
  test.equal(next, null);
307
307
 
308
- var rule = new schedule.RecurrenceRule();
309
- rule.month = 'asdfasdf';
310
- next = rule.nextInvocationDate(next);
311
- test.equal(next, null);
308
+ var rule2 = new schedule.RecurrenceRule();
309
+ rule2.month = 'asdfasdf';
310
+ var next2 = rule2.nextInvocationDate(next);
311
+ test.equal(next2, null);
312
312
 
313
313
  test.done();
314
314
  },
315
315
  "nextInvocationDate on an invalid second should return null": function(test) {
316
316
  var rule = new schedule.RecurrenceRule();
317
317
  rule.second = 60;
318
- var next = rule.nextInvocationDate(next);
318
+ var next = rule.nextInvocationDate();
319
319
  test.equal(next, null);
320
320
 
321
- var rule = new schedule.RecurrenceRule();
322
- rule.second = 'asdfasdf';
323
- next = rule.nextInvocationDate(next);
324
- test.equal(next, null);
321
+ var rule2 = new schedule.RecurrenceRule();
322
+ rule2.second = 'asdfasdf';
323
+ var next2 = rule2.nextInvocationDate();
324
+ test.equal(next2, null);
325
325
 
326
326
  test.done();
327
327
  },
328
328
  "nextInvocationDate on an invalid hour should return null": function(test) {
329
329
  var rule = new schedule.RecurrenceRule();
330
330
  rule.hour = 24;
331
- var next = rule.nextInvocationDate(next);
331
+ var next = rule.nextInvocationDate();
332
332
  test.equal(next, null);
333
333
 
334
- var rule = new schedule.RecurrenceRule();
335
- rule.hour = 'asdfasdf';
336
- next = rule.nextInvocationDate(next);
337
- test.equal(next, null);
334
+ var rule2 = new schedule.RecurrenceRule();
335
+ rule2.hour = 'asdfasdf';
336
+ var next2 = rule2.nextInvocationDate();
337
+ test.equal(next2, null);
338
338
 
339
339
  test.done();
340
340
  },
341
341
  "nextInvocationDate on an invalid date should return null": function(test) {
342
342
  var rule = new schedule.RecurrenceRule();
343
343
  rule.date = 90;
344
- var next = rule.nextInvocationDate(next);
344
+ var next = rule.nextInvocationDate();
345
345
  test.equal(next, null);
346
346
 
347
347
  // Test February
348
- var rule = new schedule.RecurrenceRule();
349
- rule.month = 1;
350
- rule.date = 30;
351
- next = rule.nextInvocationDate(next);
352
- test.equal(next, null);
348
+ var rule2 = new schedule.RecurrenceRule();
349
+ rule2.month = 1;
350
+ rule2.date = 30;
351
+ var next2 = rule2.nextInvocationDate();
352
+ test.equal(next2, null);
353
353
 
354
- var rule = new schedule.RecurrenceRule();
355
- rule.date = 'asdfasdf';
356
- next = rule.nextInvocationDate(next);
357
- test.equal(next, null);
354
+ var rule3 = new schedule.RecurrenceRule();
355
+ rule3.date = 'asdfasdf';
356
+ var next3 = rule3.nextInvocationDate();
357
+ test.equal(next3, null);
358
358
 
359
359
  test.done();
360
360
  },
361
361
  "nextInvocationDate on an invalid dayOfWeek should return null": function(test) {
362
362
  var rule = new schedule.RecurrenceRule();
363
363
  rule.dayOfWeek = 90;
364
- var next = rule.nextInvocationDate(next);
364
+ var next = rule.nextInvocationDate();
365
365
  test.equal(next, null);
366
366
 
367
- var rule = new schedule.RecurrenceRule();
368
- rule.dayOfWeek = 'asdfasdf';
369
- next = rule.nextInvocationDate(next);
370
- test.equal(next, null);
367
+ var rule2 = new schedule.RecurrenceRule();
368
+ rule2.dayOfWeek = 'asdfasdf';
369
+ var next2 = rule.nextInvocationDate();
370
+ test.equal(next2, null);
371
371
 
372
372
  test.done();
373
373
  }
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- *.sublime*
2
- .npmrc