Skip to content

Commit

Permalink
Merge pull request iriscouch#91 from smithsz/retry-on-last-seq
Browse files Browse the repository at this point in the history
Retry change request on last_seq
  • Loading branch information
jhs committed Aug 25, 2017
2 parents 58a6f38 + 1fec18e commit d27f807
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ Feed.prototype.query = function query_feed() {
return self.retry();
}

if (resp.statusCode === 404) {
destroy_response(resp);
self.log.warn('Database not found. Stopping changes feed.');
var del_er = new Error('Database not found.');
del_er.deleted = true;
del_er.last_seq = self.since;
return self.die(del_er);
}

if(resp.statusCode !== 200) {
self.log.debug('Bad changes response ' + feed_id + ': ' + resp.statusCode);
destroy_response(resp);
Expand Down Expand Up @@ -435,12 +444,10 @@ Feed.prototype.on_couch_data = function on_couch_data(change) {
change = JSON.parse(change)

//self.log.debug('Object:\n' + util.inspect(change));
if(!self.is_db_updates && 'last_seq' in change) {
self.log.warn('Stopping upon receiving a final message: ' + JSON.stringify(change))
var del_er = new Error('Database deleted after change: ' + change.last_seq)
del_er.deleted = true
del_er.last_seq = change.last_seq
return self.die(del_er)
if ('last_seq' in change) {
self.log.debug('Found last_seq in change: retrying request');
self.since = change.last_seq;
return self.retry();
}

if(!self.is_db_updates && !change.seq)
Expand Down

0 comments on commit d27f807

Please sign in to comment.