ashishkranjan / dabr

Automatically exported from code.google.com/p/dabr
0 stars 0 forks source link

Reload when twitter returns 503 error. #113

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What would you like dabr to do?
When twitter returns a 503 error (no servers available), re-send the
request in X seconds.

How would you prefer dabr to do it?
using <meta http-equiv="refresh" content="5; URL=http://"> or javascript.

Original issue reported on code.google.com by mychemic...@gmail.com on 13 Jan 2010 at 7:24

GoogleCodeExporter commented 9 years ago
what I do is split the CURLing into a separate function and do this from 
twitter_process:

  $cr = curl_process($url, $post_data, $timeout);
  $response = $cr[0];
  $response_info = $cr[1];
  $httpcode = intval( $response_info['http_code'] );

  if ( $httpcode > 500 ) {
      $cr = curl_process($url, $post_data, $timeout);
      $response = $cr[0];
      $response_info = $cr[1];
      $httpcode = intval( $response_info['http_code'] );
  }

Original comment by ldoug...@gmail.com on 20 Jan 2010 at 1:17

GoogleCodeExporter commented 9 years ago
I suppose I could add a sleep(2); inside the if statement.

Original comment by ldoug...@gmail.com on 20 Jan 2010 at 2:47

GoogleCodeExporter commented 9 years ago
that would be better :D

Original comment by mychemic...@gmail.com on 20 Jan 2010 at 3:25

GoogleCodeExporter commented 9 years ago
this is my fix :-)
add a $retry counter in the function definition, then it should be something 
like 
this:

function twitter_process($url, $post_data = false, $retry = 0) {

then change the handle of http_code:
switch( intval( $response_info['http_code'] ) ) {
    case 201:
    case 200:
      $json = json_decode($response);
      if ($json) return $json;
      return $response;
    case 401:
      user_logout();
      theme('error', '<p>Error: Login credentials incorrect.</p>');
    case 500:    
    case 502:
    case 503:
      if( $retry < 3 ) return twitter_process( $url, $post_data, $retry + 1 );
      else theme('error', "<h2>An error occured while calling the Twitter 
API</h2><p>{$response_info['http_code']}: {$result}</p><hr><p>$url</p>");
    break;
    case 0:
    if( $response )return $response;
    if( $retry < 3 ) return twitter_process( $url, $post_data, $retry + 1 );
    theme('error', '<h2>Twitter timed out</h3><p>Dabr gave up on waiting for Twitter 
to respond. They\'re probably overloaded right now, try again in a 
minute.</p>');
    default:
      $result = json_decode( $response );
      $result = $result->error ? $result->error : $response;
      if (strlen($result) > 500) $result = 'Something broke on Twitter\'s end.';
      if( $retry < 3) return twitter_process($url, $post_data, $retry + 1 );
      theme('error', "<h2>An error occured while calling the Twitter 
API</h2><p>{$response_info['http_code']}: {$result}</p><hr><p>$url</p>");
  }
}

Original comment by felixonm...@gmail.com on 20 Jan 2010 at 2:42

GoogleCodeExporter commented 9 years ago
After seeing loads of complaints, I'm trying this.  While it seems to solve some
problems, I have managed to get a timeout after 40 seconds... so it's not 
perfect.

Original comment by terence.eden on 4 May 2010 at 2:04

GoogleCodeExporter commented 9 years ago
the retry is way too better

Original comment by mychemic...@gmail.com on 4 May 2010 at 11:50

GoogleCodeExporter commented 9 years ago
I do not believe that forcing a retry is a suitable fix for this problem. It 
may work 
great on a small scale but is definitely not appropriate for a server already 
making 
hundreds of thousands of API requests each day.

Another major issue is that some POST actions (e.g. status updates) do succeed 
regardless of error messages from Twitter, and resubmitting them is a waste of 
time and 
resources.

Original comment by david.carrington on 5 May 2010 at 9:14

GoogleCodeExporter commented 9 years ago

Original comment by terence.eden on 13 Jun 2011 at 12:31