Permalink
Browse files

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

  • Loading branch information...
1 parent 76e8811 commit e9a05617b9c39a2380b766b142146bc3aa4449c7 @francoiscote francoiscote committed Mar 29, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/processor.js
View
11 lib/processor.js
@@ -89,7 +89,7 @@ TwitterProcessor.prototype.init = function() {
TwitterProcessor.prototype._startStream = function() {
if(!this._retriesCount) {
- this._retriesCount = 1;
+ this._retriesCount = 0;
}
var self = this;
@@ -105,7 +105,7 @@ TwitterProcessor.prototype._startStream = function() {
//On new tweet
stream.on('data', function (tweet) {
- self._retriesCount = 1;
+ self._retriesCount = 0;
//Add tweet to queue
if(typeof(tweet.text) != 'undefined') {
@@ -121,7 +121,8 @@ TwitterProcessor.prototype._startStream = function() {
}
try {
if(self._retriesCount < 300) {
- self._retriesCount = self._retriesCount * 2;
+ // try after one minute, then double every other try
+ self._retriesCount = (self._retriesCount === 0)?1:self._retriesCount * 2;
}
stream.destroy();
} catch(e){}
@@ -143,11 +144,11 @@ TwitterProcessor.prototype._startStream = function() {
//Reconnect if the destroy was not intented
if(self.isStarted) {
if(self.options.debug) {
- console.log('Twitter stream reconnect in '+self._retriesCount+' second(s)');
+ console.log('Twitter stream reconnect in '+self._retriesCount+' minute(s)');
}
setTimeout(function() {
self._startStream();
- },self._retriesCount * 1000);
+ },self._retriesCount * 1000 * 60);
}
});

0 comments on commit e9a0561

Please sign in to comment.