cron 1.6.0 → 1.7.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/.travis.yml CHANGED
@@ -1,9 +1,11 @@
1
1
  language: node_js
2
2
  node_js:
3
- - "4"
4
- - "6"
5
- - "8"
6
- - "10"
3
+ - '4'
4
+ - '6'
5
+ - '8'
6
+ - '10'
7
7
  notifications:
8
8
  email:
9
9
  on_success: never
10
+ slack:
11
+ secure: hHI67BDSUiJQeEiJI/+XJzR/oSsjYPoylhqY10WIZWXfs4TIrdLe513Fzt9BnDNtxpHnCqkgqCb1lF8gNkkOhJKezfDwOZK6HKpNp+zfn7WqBxL0VB3rPw3JoOO9JWoELwV2LyUutbw7m4+OMO45eWgQmQM4mddUMHjyV0awa7A=
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [v1.6.0] - 2018-11-15
2
+ - 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
3
+ - GH-390 - better handling of real dates which are in the past by Nick Campbell <nicholas.j.campbell@gmail.com> in 7cbcc984aea6ec063e38829f68eb9bc0dfb1c775
package/README.md CHANGED
@@ -108,6 +108,9 @@ Gotchas
108
108
  granularity for all dates to seconds, but felt that it wasn't a huge problem
109
109
  so long as you were made aware. If this becomes more of an issue, We can
110
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)
111
114
 
112
115
 
113
116
  API
@@ -0,0 +1,9 @@
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/lib/cron.js CHANGED
@@ -143,7 +143,7 @@
143
143
  }
144
144
 
145
145
  if (this.realDate) {
146
- const diff = moment().diff(date);
146
+ const diff = moment().diff(date, 's');
147
147
  if (diff > 0) {
148
148
  throw new Error('WARNING: Date in past. Will never be fired.');
149
149
  }
@@ -294,9 +294,17 @@
294
294
  Object.keys(this.hour).length !== 24
295
295
  ) {
296
296
  origDate = moment(date);
297
+ var curHour = date.hours();
297
298
  date.hours(
298
- date.hours() === 23 && diff > 86400000 ? 0 : date.hours() + 1
299
+ date.hours() === 23 && diff > 86400000 ? 0 : date.hours() + 1
299
300
  );
301
+ /*
302
+ * Moment Date will not allow you to set the time to 2 AM if there is no 2 AM (on the day we change the clock)
303
+ * We will therefore jump to 3AM if time stayed at 1AM
304
+ */
305
+ if(curHour === date.hours()){
306
+ date.hours(date.hours() + 2);
307
+ }
300
308
  date.minutes(0);
301
309
  date.seconds(0);
302
310
  if (date <= origDate) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cron",
3
3
  "description": "Cron jobs for your node",
4
- "version": "1.6.0",
4
+ "version": "1.7.0",
5
5
  "author": "Nick Campbell <nicholas.j.campbell@gmail.com> (http://github.com/ncb000gt)",
6
6
  "bugs": {
7
7
  "url": "http://github.com/kelektiv/node-cron/issues"
@@ -18,18 +18,18 @@
18
18
  "moment-timezone": "^0.5.x"
19
19
  },
20
20
  "devDependencies": {
21
- "mocha": "~5.1.x",
22
- "chai": "~4.1.x",
23
- "sinon": "~1.12.x",
24
- "eslint": "~5.3.x",
25
- "eslint-config-prettier": "~3.0.x",
26
- "eslint-config-standard": "~11.0.x",
27
- "eslint-plugin-import": "~2.14.x",
28
- "eslint-plugin-node": "~7.0.x",
29
- "eslint-plugin-prettier": "~2.6.x",
30
- "eslint-plugin-promise": "~3.8.x",
31
- "eslint-plugin-standard": "~3.1.x",
32
- "prettier": "~1.14.x"
21
+ "mocha": "~5.2.x",
22
+ "chai": "~4.2.x",
23
+ "sinon": "~7.2.x",
24
+ "eslint": "~5.13.x",
25
+ "eslint-config-prettier": "~4.0.x",
26
+ "eslint-config-standard": "~12.0.x",
27
+ "eslint-plugin-import": "~2.16.x",
28
+ "eslint-plugin-node": "~8.0.x",
29
+ "eslint-plugin-prettier": "~3.0.x",
30
+ "eslint-plugin-promise": "~4.0.x",
31
+ "eslint-plugin-standard": "~4.0.x",
32
+ "prettier": "~1.16.x"
33
33
  },
34
34
  "keywords": [
35
35
  "cron",
@@ -739,7 +739,9 @@ describe('cron', function() {
739
739
 
740
740
  it('should not fire if time was adjusted back', function() {
741
741
  var c = 0;
742
- var clock = sinon.useFakeTimers('setTimeout');
742
+ var clock = sinon.useFakeTimers({
743
+ toFake: ['setTimeout']
744
+ });
743
745
 
744
746
  var job = new cron.CronJob(
745
747
  '0 * * * * *',
@@ -867,6 +869,31 @@ describe('cron', function() {
867
869
  expect(c).to.eql(8);
868
870
  });
869
871
 
872
+ it('should trigger onTick at midnight', function() {
873
+ var c = 0;
874
+ var d = new Date('12/31/2014');
875
+ d.setSeconds(59);
876
+ d.setMinutes(59);
877
+ d.setHours(23);
878
+ var clock = sinon.useFakeTimers(d.getTime());
879
+
880
+ var job = new cron.CronJob({
881
+ cronTime: '00 * * * * *',
882
+ onTick: function() {
883
+ c++;
884
+ },
885
+ start: true,
886
+ timeZone: 'UTC'
887
+ });
888
+
889
+ clock.tick(1000); // move clock 1 second
890
+ expect(c).to.eql(1);
891
+
892
+ clock.restore();
893
+ job.stop();
894
+ expect(c).to.eql(1);
895
+ });
896
+
870
897
  it('should run every day UTC', function() {
871
898
  var c = 0;
872
899
  var d = new Date('12/31/2014');
@@ -170,7 +170,7 @@ describe('crontime', function() {
170
170
  });
171
171
 
172
172
  it('should test next real date', function() {
173
- var initialDate = new Date()
173
+ var initialDate = new Date();
174
174
  var ct = new cron.CronTime(initialDate);
175
175
 
176
176
  var nextDate = new Date();