changelog_bot (changelog_bot) wrote in changelog,
changelog_bot
changelog_bot
changelog

[ljcom] r11684: LJSV-1266: Twitter digest doesn't work f...

Committer: nnikulochkina
LJSV-1266: Twitter digest doesn't work for some users
Retry 'user_timeline' request if 502 error has occured
U   trunk/cgi-bin/LJ/Client/Twitter.pm
Modified: trunk/cgi-bin/LJ/Client/Twitter.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Twitter.pm	2012-04-10 11:07:08 UTC (rev 11683)
+++ trunk/cgi-bin/LJ/Client/Twitter.pm	2012-04-10 13:27:40 UTC (rev 11684)
@@ -315,12 +315,9 @@
             return;
         } elsif ( $res->code >= 500 && $res->code < 600 ) {
             # 50x codes (which indicate a server error) only get
-            # printed if we have an environment flag on
-            if ( $ENV{'LJ_DEBUG_TWITTER_CONNECTIVITY'} ) {
-                $u->log_event ("twitter_failed", { text => $res->status_line } )
-                    if $opts{'call_from_digest'};
-                die "twitter connectivity error: " . $res->status_line;
-            }
+	    $u->log_event ("twitter_failed", { text => $res->status_line } )
+		if $opts{'call_from_digest'};
+	    die "twitter connectivity error: " . $res->status_line;
             return;
         } else {
             $u->log_event ("twitter_failed", { text => $res->status_line } )
@@ -461,15 +458,33 @@
         return [];
     }
 
-    my $res = LJ::Client::Twitter->call(
-        'api_method' => 'statuses/user_timeline',
-        'user' => $u,
-        'http_method' => 'GET',
-        'params' => { 'count'       => $LJ::TWITTER_RECENT_FEED_DEPTH,
-                      'include_rts' => 1, }, # with retweets
-        %$opts,
-    );
+    my $res;
+    my $retry_number = $LJ::TWITTER_API_USER_TIMELINE_RETRY || 1;
 
+  RETRY:
+    foreach my $retry_count ( 1..$retry_number ) {
+	eval {
+	    $res = LJ::Client::Twitter->call(
+                'api_method' => 'statuses/user_timeline',
+                'user' => $u,
+                'http_method' => 'GET',
+	        'params' => { 'count'       => $LJ::TWITTER_RECENT_FEED_DEPTH,
+		              'include_rts' => 1, }, # with retweets
+                %$opts,
+	    );
+        };
+
+	if( $@ && $@ =~ /twitter connectivity error: 502/ && $retry_count < $retry_number ) {
+	    # we recieved 502 error
+	    # wait and try again
+	    sleep 1;
+	} elsif ($@) {
+	    die $@;
+	} else {
+	    last RETRY;
+	}
+    }
+
     return [ map { LJ::Client::Twitter::Tweet->from_hash($_) } 
              grep { not $_->{in_reply_to_status_id} } # without replies
              @$res ];

Tags: changelog_bot, ljcom, nnikulochkina, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments