Changeset 602

Show
Ignore:
Timestamp:
03/06/07 18:18:26 (6 years ago)
Author:
max
Message:

Rex handles network flakiness better

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • grabbers/rex

    r584 r602  
    33# "Rex" 
    44 
    5 my $version  = '3.5.0'; 
     5my $version  = '3.4.6'; 
    66 
    77# An Australian TV Guide Grabber (a.k.a. tv_grab_au) 
     
    7777# 3.4.4   : Bugfix : --dump-cache works 
    7878# 3.4.5   : Bugfix : support regions with multiple channels of same name 
     79# 3.4.6   : Bugfix : more reliable dying on network failure 
    7980 
    8081use strict; 
     
    443444 
    444445  # Set initial cookie 
    445   get_page($DATASOURCE); 
     446  unless (get_page($DATASOURCE, 5)) # Try hard to fetch main page 
     447  { 
     448      print "Unable to fetch main datasource page. No connectivity? Exiting.\n"; 
     449      print stats(1); 
     450      die "Can't fetch main page."; 
     451  } 
    446452 
    447453  # Set region/service cookie 
    448   post_page($DATASOURCE_SETUP, 
    449         [ 'fta_region_id' => $opt->{'region'} ]); 
     454  unless (post_page($DATASOURCE_SETUP, [ 'fta_region_id' => $opt->{'region'} ])) 
     455  { 
     456      print "ERROR: Unable to set region/service cookie.\n"; 
     457      print stats(1); 
     458      die "Can't set region/service cookie."; 
     459  } 
    450460 
    451461  $ua->cookie_jar()->scan(\&refresh_sid); 
     
    577587sub get_page 
    578588{ 
    579   my ($url) = @_; 
     589  my ($url, $retries) = @_; 
    580590  my $request = GET $url; 
    581   return fetch_page($request); 
     591  return fetch_page($request, $retries); 
    582592} 
    583593 
     
    591601sub fetch_page 
    592602{ 
    593   my ($request) = @_; 
     603  my ($request, $retries) = @_; 
    594604   
    595605  $request->uri() =~ s/^http:\/\//$WW/ if $opt->{warper}; 
     
    598608 
    599609  print "Fetching: " . $request->as_string() . "\n" if ($debug); 
     610  $retries ||= 2; 
    600611  my $response; 
    601   for my $c (1..2) { 
     612  for my $c (1..$retries) { 
    602613    print "Attempt #$c.\n" if ($debug); 
    603614    $response = $ua->request($request); 
     
    615626        while ($r) { print "    ", $r->base, "\n"; $r = $r->previous } 
    616627    } 
    617     # Network down 
    618     if ($count_bad > 10 and $count_dl == 0) 
    619     { 
    620         print "ERROR! Unable to download anything useful. Smells like a " . 
    621               "network problem. Exiting.\n"; 
     628    if ($count_dl and ($count_bad > ($count_dl * 3))) 
     629    { 
     630        print "Too many network failures. Exiting.\n"; 
    622631        print stats(1); 
    623         die "No connectivity"; 
     632        die "Too many network failures."; 
    624633    } 
    625634    return undef; 
  • status

    r601 r602  
    11application     shepherd            0.4.76 
    22grabber         yahoo7widget        1.81 
    3 grabber         rex                 3.4.5 
     3grabber         rex                 3.4.6 
    44grabber         abc_website         2.11 
    55grabber         abc2_website        2.11