Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

twitter connection retries: after 1 minute, then double every other try

  • Loading branch information...
commit e9a05617b9c39a2380b766b142146bc3aa4449c7 1 parent 76e8811
François Côté francoiscote authored

Showing 1 changed file with 6 additions and 5 deletions. Show diff stats Hide diff stats

  1. +6 5 lib/processor.js
11 lib/processor.js
@@ -89,7 +89,7 @@ TwitterProcessor.prototype.init = function() {
89 89 TwitterProcessor.prototype._startStream = function() {
90 90
91 91 if(!this._retriesCount) {
92   - this._retriesCount = 1;
  92 + this._retriesCount = 0;
93 93 }
94 94
95 95 var self = this;
@@ -105,7 +105,7 @@ TwitterProcessor.prototype._startStream = function() {
105 105 //On new tweet
106 106 stream.on('data', function (tweet) {
107 107
108   - self._retriesCount = 1;
  108 + self._retriesCount = 0;
109 109
110 110 //Add tweet to queue
111 111 if(typeof(tweet.text) != 'undefined') {
@@ -121,7 +121,8 @@ TwitterProcessor.prototype._startStream = function() {
121 121 }
122 122 try {
123 123 if(self._retriesCount < 300) {
124   - self._retriesCount = self._retriesCount * 2;
  124 + // try after one minute, then double every other try
  125 + self._retriesCount = (self._retriesCount === 0)?1:self._retriesCount * 2;
125 126 }
126 127 stream.destroy();
127 128 } catch(e){}
@@ -143,11 +144,11 @@ TwitterProcessor.prototype._startStream = function() {
143 144 //Reconnect if the destroy was not intented
144 145 if(self.isStarted) {
145 146 if(self.options.debug) {
146   - console.log('Twitter stream reconnect in '+self._retriesCount+' second(s)');
  147 + console.log('Twitter stream reconnect in '+self._retriesCount+' minute(s)');
147 148 }
148 149 setTimeout(function() {
149 150 self._startStream();
150   - },self._retriesCount * 1000);
  151 + },self._retriesCount * 1000 * 60);
151 152 }
152 153 });
153 154

0 comments on commit e9a0561

Please sign in to comment.
Something went wrong with that request. Please try again.