Comparing version 0.8.0 to 0.9.0
@@ -32,4 +32,5 @@ // Core routines for event emitters | ||
var INITIAL_RETRY_DELAY = 1000; | ||
var RESPONSE_GRACE_TIME = 5000; | ||
var FEED_PARAMETERS = ['since', 'limit', 'feed', 'heartbeat', 'filter', 'include_docs']; | ||
var FEED_PARAMETERS = ['since', 'limit', 'feed', 'heartbeat', 'filter', 'include_docs', 'view', 'style']; | ||
@@ -139,3 +140,9 @@ var EventEmitter = events.EventEmitter2 || events.EventEmitter; | ||
if(self.since < 0) { | ||
if(self.since == -1) { | ||
self.log.debug('Query since '+self.since+' will start at ' + db.update_seq) | ||
self.since = db.update_seq | ||
} else if(self.since < 0) { | ||
if(isNaN(db.update_seq)) | ||
return self.emit('error', new Error('DB requires specific id in "since"')); | ||
self.log.debug('Query since '+self.since+' will start at ' + (db.update_seq + self.since + 1)) | ||
@@ -185,3 +192,2 @@ self.since = db.update_seq + self.since + 1 | ||
, encoding: 'utf-8' | ||
, onResponse: on_feed_response | ||
} | ||
@@ -200,9 +206,13 @@ | ||
var feed_request = request(req) | ||
feed_request.on('response', function() { | ||
feed_request.on('response', function(res) { | ||
self.log.debug('Remove feed from agent pool: ' + feed_id) | ||
feed_request.req.socket.emit('agentRemove') | ||
// Simulate the old onResponse option. | ||
on_feed_response(null, res, res.body) | ||
}) | ||
// The response headers must arrive within one heartbeat. | ||
var response_timer = setTimeout(response_timed_out, self.heartbeat) | ||
var response_timer = setTimeout(response_timed_out, self.heartbeat + RESPONSE_GRACE_TIME) | ||
, timed_out = false | ||
@@ -336,2 +346,5 @@ | ||
var self = this | ||
if (self.dead) | ||
return | ||
@@ -520,3 +533,3 @@ if(! self.pending.wait_timer) | ||
if(change.seq <= self.since) { | ||
if(change.seq == self.since) { | ||
self.log.debug('Bad seq value ' + change.seq + ' since=' + self.since); | ||
@@ -526,3 +539,3 @@ return destroy_req(self.pending.request); | ||
if(!self.caught_up && change.seq >= self.original_db_seq) { | ||
if(!self.caught_up && change.seq == self.original_db_seq) { | ||
self.caught_up = true | ||
@@ -529,0 +542,0 @@ self.emit('catchup', change.seq) |
{ "name": "follow" | ||
, "version": "0.8.0" | ||
, "version": "0.9.0" | ||
, "author": { "name": "Jason Smith" | ||
@@ -11,5 +11,5 @@ , "email": "jhs@iriscouch.com" } | ||
, "engines": [ "node" ] | ||
, "dependencies" : { "request" : "~2.2.5" | ||
, "dependencies" : { "request" : "~2.16.2" | ||
} | ||
, "devDependencies": { "tap": "~0.1.3" | ||
, "devDependencies": { "tap": "~0.4.0" | ||
, "traceback": "~0.3.0" | ||
@@ -16,0 +16,0 @@ } |
@@ -14,4 +14,5 @@ # Follow: CouchDB changes notifier for NodeJS | ||
follow("https://example.iriscouch.com/boogie", function(error, change) { | ||
if(!error) | ||
if(!error) { | ||
console.log("Got change number " + change.seq + ": " + change.id); | ||
} | ||
}) | ||
@@ -111,2 +112,24 @@ ``` | ||
<a name="pause"></a> | ||
## Pause and Resume | ||
A Follow feed is a Node.js stream. If you get lots of changes and processing them takes a while, use `.pause()` and `.resume()` as needed. Pausing guarantees that no new events will fire. Resuming guarantees you'll pick up where you left off. | ||
```javascript | ||
follow("https://example.iriscouch.com/boogie", function(error, change) { | ||
var feed = this | ||
if(change.seq == 1) { | ||
console.log('Uh oh. The first change takes 30 hours to process. Better pause.') | ||
feed.pause() | ||
setTimeout(function() { feed.resume() }, 30 * 60 * 60 * 1000) | ||
} | ||
// ... 30 hours with no events ... | ||
else | ||
console.log('No need to pause for normal change: ' + change.id) | ||
}) | ||
``` | ||
<a name="events"></a> | ||
@@ -152,8 +175,8 @@ ## Events | ||
$ ./node_modules/.bin/tap test | ||
ok test/couch.js ...................................... 10/10 | ||
ok test/follow.js ..................................... 68/68 | ||
ok test/issues/10.js .................................. 10/10 | ||
ok test/issues.js ..................................... 43/43 | ||
ok test/stream.js ................................... 299/299 | ||
$ ./node_modules/.bin/tap test/*.js test/issues/*.js | ||
ok test/couch.js ...................................... 11/11 | ||
ok test/follow.js ..................................... 69/69 | ||
ok test/issues.js ..................................... 44/44 | ||
ok test/stream.js ................................... 300/300 | ||
ok test/issues/10.js .................................. 11/11 | ||
total ............................................... 435/435 | ||
@@ -160,0 +183,0 @@ |
@@ -55,3 +55,4 @@ var tap = require('tap') | ||
var host = 'localhost:5984' | ||
follow_req.req.agent.sockets[host].forEach(function(socket, i) { | ||
var sockets = follow_req.req.agent.sockets[host] || [] | ||
sockets.forEach(function(socket, i) { | ||
t.isNot(socket, follow_req.req.connection, 'The changes follower is not socket '+i+' in the agent pool') | ||
@@ -58,0 +59,0 @@ }) |
@@ -378,4 +378,7 @@ var tap = require('tap') | ||
var uri = couch.DB + '/_changes?feed=' + type | ||
var req = request({'uri':uri, 'onResponse':true}, on_response) | ||
var req = request({'uri':uri}) | ||
// Compatibility with the old onResponse option. | ||
req.on('response', function(res) { on_response(null, res, res.body) }) | ||
// Disconnect the continuous feed after a while. | ||
@@ -461,2 +464,3 @@ if(type == 'continuous') | ||
, firsts = {'feed':null, 'http':null, 'request':null} | ||
function ev(type, value) { | ||
@@ -495,3 +499,4 @@ var now = new Date | ||
var req = request({'uri':uri, 'onResponse':feed_response}) | ||
var req = request({'uri':uri}) | ||
req.on('response', function(res) { feed_response(null, res, res.body) }) | ||
req.on('error', function(er) { ev('request', er) }) | ||
@@ -545,7 +550,7 @@ req.on('close', function() { ev('request', 'close') }) | ||
if(type == 'continuous') { | ||
t.ok(events.http.length >= 10, 'Should have at least ten '+type+' HTTP events') | ||
t.ok(events.request.length >= 10, 'Should have at least ten '+type+' request events') | ||
t.ok(events.http.length >= 7, 'Should have at least seven '+type+' HTTP events') | ||
t.ok(events.request.length >= 7, 'Should have at least seven '+type+' request events') | ||
t.ok(events.http.length < 200, type+' HTTP events ('+events.http.length+') stop before 100') | ||
t.ok(events.request.length < 200, type+' request events ('+events.request.length+') stop before 100') | ||
t.ok(events.http.length < 200, type+' HTTP events ('+events.http.length+') stop before 200') | ||
t.ok(events.request.length < 200, type+' request events ('+events.request.length+') stop before 200') | ||
@@ -552,0 +557,0 @@ var frac = events.http.length / bulk_docs_count |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
222674
2879
189
+ Addedasync@0.2.10(transitive)
+ Addedaws-sign@0.2.1(transitive)
+ Addedboom@0.3.8(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcookie-jar@0.2.0(transitive)
+ Addedcryptiles@0.1.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedforever-agent@0.2.0(transitive)
+ Addedform-data@0.0.10(transitive)
+ Addedhawk@0.10.2(transitive)
+ Addedhoek@0.7.6(transitive)
+ Addedjson-stringify-safe@3.0.0(transitive)
+ Addedmime@1.2.11(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.2.0(transitive)
+ Addedqs@0.5.6(transitive)
+ Addedrequest@2.16.6(transitive)
+ Addedsntp@0.1.4(transitive)
+ Addedtunnel-agent@0.2.0(transitive)
- Removedrequest@2.2.9(transitive)
Updatedrequest@~2.16.2