switched from concurrent to serial link checking - LWP::Parallel::UserAgent is no longer necessary

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1131312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2011-06-04 04:47:43 +00:00
parent c1fe16763f
commit 513113259a
1 changed files with 22 additions and 25 deletions

View File

@ -28,9 +28,7 @@ use strict;
use warnings;
use Getopt::Long;
use POSIX qw/strftime/;
use LWP::Simple;
use HTTP::Request;
require LWP::Parallel::UserAgent;
use LWP::UserAgent;
my $version;
my $interval = 300;
@ -57,11 +55,14 @@ my $apache_url_suffix = "lucene/java/$version/lucene-$version.tgz.asc";
my $apache_mirrors_list_url = "http://www.apache.org/mirrors/";
my $maven_url = "http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
my $agent = LWP::UserAgent->new();
$agent->timeout(2);
my $maven_available = 0;
my @apache_mirrors = ();
my $apache_mirrors_list_page = get($apache_mirrors_list_url);
my $apache_mirrors_list_page = $agent->get($apache_mirrors_list_url)->decoded_content;
if (defined($apache_mirrors_list_page)) {
#<TR>
# <TD ALIGN=RIGHT><A HREF="http://apache.dattatec.com/">apache.dattatec.com</A>&nbsp;&nbsp;<A HREF="http://apache.dattatec.com/">@</A></TD>
@ -86,22 +87,21 @@ if (defined($apache_mirrors_list_page)) {
my $num_apache_mirrors = $#apache_mirrors;
my $sleep_interval = 0;
while (1) {
my $start = time();
print "\n", strftime('%d-%b-%Y %H:%M:%S', localtime);
print "\nPolling $#apache_mirrors Apache Mirrors";
print " and Maven Central" unless ($maven_available);
print "...\n";
unless ($maven_available) {
my $content = get($maven_url);
$maven_available = defined($content);
}
my $start = time();
$maven_available = (200 == $agent->get($maven_url)->code)
unless ($maven_available);
@apache_mirrors = &check_mirrors;
my $stop = time();
$sleep_interval = $interval - ($stop - $start);
my $num_downloadable_apache_mirrors
= $num_apache_mirrors - $#apache_mirrors;
print "\n", strftime('%d-%b-%Y %H:%M:%S', localtime), "\n";
my $num_downloadable_apache_mirrors = $num_apache_mirrors - $#apache_mirrors;
print "$version is ", ($maven_available ? "" : "not "),
"downloadable from Maven Central.\n";
printf "$version is downloadable from %d/%d Apache Mirrors (%0.1f%%)\n",
@ -110,22 +110,19 @@ while (1) {
last if ($maven_available && 0 == $#apache_mirrors);
my $stop = time();
my $sleep_interval = $interval - ($stop - $start);
sleep($sleep_interval) if ($sleep_interval > 0);
if ($sleep_interval > 0) {
print "Sleeping for $sleep_interval seconds...\n";
sleep($sleep_interval)
}
}
sub check_mirrors {
my $agent = LWP::Parallel::UserAgent->new();
$agent->timeout(30);
$agent->redirect(1); # follow redirects
$agent->register(HTTP::Request->new(GET=>$_)) for (@apache_mirrors);
my $entries = $agent->wait();
my @not_yet_downloadable_apache_mirrors;
for my $entry (keys %$entries) {
my $response = $entries->{$entry}->response;
push @not_yet_downloadable_apache_mirrors, $response->request->uri
unless (200 == $response->code);
for my $mirror (@apache_mirrors) {
push @not_yet_downloadable_apache_mirrors, $mirror
unless (200 == $agent->get($mirror)->code);
print ".";
}
print "\n";
return @not_yet_downloadable_apache_mirrors;
}