You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2016/06/28 15:11:16 UTC
incubator-streams git commit: Changed handleTwitterError() to use
RateLimitStatus for sleep/reset
Repository: incubator-streams
Updated Branches:
refs/heads/master 0e7fbcb6b -> 77f3e8a38
Changed handleTwitterError() to use RateLimitStatus for sleep/reset
Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/77f3e8a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/77f3e8a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/77f3e8a3
Branch: refs/heads/master
Commit: 77f3e8a38316312ebee74af143f5703fbab36541
Parents: 0e7fbcb
Author: Joey Frazee <jo...@icloud.com>
Authored: Fri May 27 20:20:36 2016 -0500
Committer: Joey Frazee <jo...@icloud.com>
Committed: Fri May 27 20:22:04 2016 -0500
----------------------------------------------------------------------
.../twitter/provider/TwitterErrorHandler.java | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/77f3e8a3/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterErrorHandler.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterErrorHandler.java b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterErrorHandler.java
index fd063a1..51236ba 100644
--- a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterErrorHandler.java
+++ b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterErrorHandler.java
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import twitter4j.Twitter;
import twitter4j.TwitterException;
+import twitter4j.RateLimitStatus;
/**
* Handle expected and unexpected exceptions.
@@ -35,7 +36,7 @@ public class TwitterErrorHandler
@Deprecated
public static int handleTwitterError(Twitter twitter, Exception exception) {
- return handleTwitterError( twitter, null, exception);
+ return handleTwitterError(twitter, null, exception);
}
public static int handleTwitterError(Twitter twitter, Long id, Exception exception)
@@ -45,12 +46,21 @@ public class TwitterErrorHandler
TwitterException e = (TwitterException)exception;
if(e.exceededRateLimitation())
{
- LOGGER.warn("Rate Limit Exceeded");
+ long millisUntilReset = retry;
+
+ final RateLimitStatus rateLimitStatus = e.getRateLimitStatus();
+ if (rateLimitStatus != null) {
+ millisUntilReset = rateLimitStatus.getSecondsUntilReset() * 1000;
+ }
+
+ LOGGER.warn("Rate Limit Exceeded. Will retry in {} seconds...", millisUntilReset / 1000);
+
try {
- Thread.sleep(retry);
+ Thread.sleep(millisUntilReset);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
+
return 1;
}
else if(e.isCausedByNetworkIssue())