Permalink
Browse files

pause without restart when out of api limit

  • Loading branch information...
1 parent 4a17047 commit adc5bff96de9405d74d229e928e3f7343e35a444 @bobrik committed May 6, 2012
Showing with 11 additions and 7 deletions.
  1. +11 −7 node_modules/ListWatcher/ListWatcher.js
View
18 node_modules/ListWatcher/ListWatcher.js
@@ -19,7 +19,8 @@ module.exports = {
restart_timeout : 10000,
followers_wait_timeout : 100,
rate_limit_check_timeout : 1000,
- followers_update_timeout : 60000
+ followers_update_timeout : 60000,
+ pause_timeout : 10000
},
loggers: {},
@@ -122,10 +123,7 @@ module.exports = {
", " + (result.reset_time_in_seconds - now) +
" seconds to go");
- if (self.started && result.reset_time_in_seconds > now) {
- self.started = false;
- self.scheduleRestart(result.reset_time_in_seconds - now);
- }
+ self.paused = result.remaining_hits <= 0;
}
if (self.started) {
@@ -154,7 +152,7 @@ module.exports = {
self.getLogger("error").write(error);
if (self.started) {
- self.getLogger("activity").write("Getting followeres failed, restarting");
+ self.getLogger("activity").write("Getting followers failed, restarting");
self.scheduleRestart();
}
@@ -187,7 +185,13 @@ module.exports = {
if (self.started) {
if (i <= followers.length - 1) {
- queue.push({user_id: followers[i++]}, cb);
+ (function next() {
+ if (self.paused) {
+ return setTimeout(next, self.getConfig().pause_timeout);
+ }
+
+ queue.push({user_id: followers[i++]}, cb);
+ })();
} else {
if (!restarted) {
restarted = true;

0 comments on commit adc5bff

Please sign in to comment.