Skip to content

Commit 4e7f948

Browse files
author
Dustin Larimer
authored
Merge pull request #85 from keen/dustin-fix-queue-hanging
v.1.2.1 Fix queue polling
2 parents 3732835 + 2a4ea84 commit 4e7f948

File tree

11 files changed

+57
-29
lines changed

11 files changed

+57
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
**BREAKING:**
77
**CHANGE:**
88
-->
9+
<a name="1.2.1"></a>
10+
# 1.2.1 Fix queue polling
11+
12+
**FIXED:**
13+
* Fixed a queue polling issue (#84) to prevent queue from polling until events are added to the queue, allowing scripts to close properly when queues are _not_ used
14+
* Clear polling loop prior to replacing queue with a new one
15+
916
<a name="1.2.0"></a>
1017
# 1.2.0 Fix queue exiting
1118

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $ npm install keen-tracking --save
1212
Or load it from our CDN:
1313

1414
```html
15-
<script src="https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.2.0.min.js"></script>
15+
<script src="https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.2.1.min.js"></script>
1616
```
1717

1818
[Read about more installation options here](./docs/installation.md)

dist/keen-tracking.js

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/keen-tracking.min.js

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ npm install keen-tracking --save
99
Or load it from our CDN:
1010

1111
```html
12-
<script src="https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.2.0.min.js"></script>
12+
<script src="https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.2.1.min.js"></script>
1313
```
1414

1515
Prefer asynchronous loading? Copy/paste this snippet of JavaScript above the `</head>` tag of your page to load the tracking library asynchronously. This technique sneaks the library into your page without significantly impacting page load speed.
@@ -19,7 +19,7 @@ Prefer asynchronous loading? Copy/paste this snippet of JavaScript above the `</
1919
// Loads the library asynchronously from any URI
2020
!function(name,path,ctx){
2121
var latest,prev=name!=='Keen'&&window.Keen?window.Keen:false;ctx[name]=ctx[name]||{ready:function(fn){var h=document.getElementsByTagName('head')[0],s=document.createElement('script'),w=window,loaded;s.onload=s.onreadystatechange=function(){if((s.readyState&&!(/^c|loade/.test(s.readyState)))||loaded){return}s.onload=s.onreadystatechange=null;loaded=1;latest=w.Keen;if(prev){w.Keen=prev}else{try{delete w.Keen}catch(e){w.Keen=void 0}}ctx[name]=latest;ctx[name].ready(fn)};s.async=1;s.src=path;h.parentNode.insertBefore(s,h)}}
22-
}('Keen','https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.2.0.min.js',this);
22+
}('Keen','https://d26b395fwzu5fz.cloudfront.net/keen-tracking-1.2.1.min.js',this);
2323
2424
// Executes when the library is loaded and ready
2525
Keen.ready(function(){

gulpfile.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var gulp = require('gulp'),
44
var aws = require('gulp-awspublish'),
55
browserify = require('browserify'),
66
buffer = require('vinyl-buffer'),
7-
compress = require('gulp-yuicompressor')
87
connect = require('gulp-connect'),
98
del = require('del'),
109
karma = require('karma').server,
@@ -17,6 +16,7 @@ var aws = require('gulp-awspublish'),
1716
source = require('vinyl-source-stream'),
1817
sourcemaps = require('gulp-sourcemaps'),
1918
stripComments = require('gulp-strip-comments'),
19+
uglify = require('gulp-uglify'),
2020
util = require('gulp-util');
2121

2222

@@ -52,17 +52,14 @@ gulp.task('build:browserify', function() {
5252

5353
gulp.task('build:minify', ['build:browserify'], function(){
5454
return gulp.src(['./dist/' + pkg.name + '.js'])
55-
.pipe(compress({ type: 'js' }))
55+
.pipe(uglify())
5656
.pipe(rename({ suffix: '.min' }))
5757
.pipe(gulp.dest('./dist/'));
5858
});
5959

6060
gulp.task('minify-loader', function(){
6161
return gulp.src(['./lib/browser-async.js'])
62-
.pipe(compress({
63-
nomunge: 0,
64-
type: 'js'
65-
}))
62+
.pipe(uglify())
6663
.pipe(rename({ basename: 'keen-loader', suffix: '.min' }))
6764
.pipe(gulp.dest('./dist/'));
6865
});

lib/defer-events.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function deferEvent(eventCollection, eventBody){
2020
this.queue.events[eventCollection] = this.queue.events[eventCollection] || [];
2121
this.queue.events[eventCollection].push(eventBody);
2222
this.queue.capacity++;
23+
if (!this.queue.timer) {
24+
this.queue.start();
25+
}
2326
this.emit('deferEvent', eventCollection, eventBody);
2427
return this;
2528
}
@@ -36,6 +39,9 @@ function deferEvents(eventsHash){
3639
self.queue.events[eventCollection] = self.queue.events[eventCollection] || [];
3740
self.queue.events[eventCollection] = self.queue.events[eventCollection].concat(eventList);
3841
self.queue.capacity = self.queue.capacity + eventList.length;
42+
if (!self.queue.timer) {
43+
self.queue.start();
44+
}
3945
});
4046
self.emit('deferEvents', eventsHash);
4147
return self;
@@ -61,6 +67,7 @@ function recordDeferredEvents(){
6167
clonedQueueEvents;
6268

6369
if (self.queue.capacity > 0) {
70+
self.queue.pause();
6471
clonedQueueConfig = JSON.parse(JSON.stringify(self.queue.config));
6572
clonedQueueEvents = JSON.parse(JSON.stringify(self.queue.events));
6673
self.queue = queue();

lib/utils/queue.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ function queue() {
1515
};
1616
this.interval = 0;
1717
this.timer = null;
18-
19-
this.start();
2018
return this;
2119
}
2220

@@ -26,7 +24,7 @@ queue.prototype.check = function() {
2624
if (shouldFlushQueue(this)) {
2725
this.flush();
2826
}
29-
if (this.config.interval === 0) {
27+
if (this.config.interval === 0 || this.capacity === 0) {
3028
this.pause();
3129
}
3230
return this;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "keen-tracking",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Data Collection SDK for Keen IO",
55
"main": "lib/server.js",
66
"browser": "lib/browser.js",
@@ -42,6 +42,7 @@
4242
"gulp-replace": "^0.5.3",
4343
"gulp-sourcemaps": "^1.5.2",
4444
"gulp-strip-comments": "^1.0.1",
45+
"gulp-uglify": "^1.5.2",
4546
"gulp-util": "^3.0.4",
4647
"gulp-yuicompressor": "0.0.3",
4748
"karma": "^0.12.32",

test/unit/modules/defer-events-spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,24 @@ describe('.deferEvent(s) methods', function() {
9595
this.client.recordDeferredEvents();
9696
});
9797

98+
it('should not have an internal queue timer until an event is added to the queue', function(){
99+
assert.isNull(this.client.queue.timer);
100+
this.client.deferEvent('single-deferred-event', { prop: true });
101+
assert.ok(this.client.queue.timer);
102+
});
103+
104+
it('should not have an internal queue timer until multiple events are added to the queue', function(){
105+
assert.isNull(this.client.queue.timer);
106+
this.client.deferEvents({
107+
'deferred event': [{ test: 'data' }, { test: 'none' }],
108+
'another event': [{ test: 'data' }]
109+
});
110+
assert.ok(this.client.queue.timer);
111+
});
112+
98113
it('should clear internal queue timer when .queueInterval() is set to 0', function(){
114+
assert.isNull(this.client.queue.timer);
115+
this.client.deferEvent('single-deferred-event', { prop: true });
99116
assert.ok(this.client.queue.timer);
100117
this.client.queueInterval(0);
101118
assert.isNull(this.client.queue.timer);

0 commit comments

Comments
 (0)