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 warnings;
use Getopt::Long; use Getopt::Long;
use POSIX qw/strftime/; use POSIX qw/strftime/;
use LWP::Simple; use LWP::UserAgent;
use HTTP::Request;
require LWP::Parallel::UserAgent;
my $version; my $version;
my $interval = 300; 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 $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 $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 $maven_available = 0;
my @apache_mirrors = (); 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)) { if (defined($apache_mirrors_list_page)) {
#<TR> #<TR>
# <TD ALIGN=RIGHT><A HREF="http://apache.dattatec.com/">apache.dattatec.com</A>&nbsp;&nbsp;<A HREF="http://apache.dattatec.com/">@</A></TD> # <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 $num_apache_mirrors = $#apache_mirrors;
my $sleep_interval = 0;
while (1) { while (1) {
my $start = time(); print "\n", strftime('%d-%b-%Y %H:%M:%S', localtime);
print "\nPolling $#apache_mirrors Apache Mirrors"; print "\nPolling $#apache_mirrors Apache Mirrors";
print " and Maven Central" unless ($maven_available); print " and Maven Central" unless ($maven_available);
print "...\n"; print "...\n";
unless ($maven_available) { my $start = time();
my $content = get($maven_url); $maven_available = (200 == $agent->get($maven_url)->code)
$maven_available = defined($content); unless ($maven_available);
}
@apache_mirrors = &check_mirrors; @apache_mirrors = &check_mirrors;
my $stop = time();
$sleep_interval = $interval - ($stop - $start);
my $num_downloadable_apache_mirrors my $num_downloadable_apache_mirrors = $num_apache_mirrors - $#apache_mirrors;
= $num_apache_mirrors - $#apache_mirrors;
print "\n", strftime('%d-%b-%Y %H:%M:%S', localtime), "\n";
print "$version is ", ($maven_available ? "" : "not "), print "$version is ", ($maven_available ? "" : "not "),
"downloadable from Maven Central.\n"; "downloadable from Maven Central.\n";
printf "$version is downloadable from %d/%d Apache Mirrors (%0.1f%%)\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); last if ($maven_available && 0 == $#apache_mirrors);
my $stop = time(); if ($sleep_interval > 0) {
my $sleep_interval = $interval - ($stop - $start); print "Sleeping for $sleep_interval seconds...\n";
sleep($sleep_interval) if ($sleep_interval > 0); sleep($sleep_interval)
}
} }
sub check_mirrors { 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; my @not_yet_downloadable_apache_mirrors;
for my $entry (keys %$entries) { for my $mirror (@apache_mirrors) {
my $response = $entries->{$entry}->response; push @not_yet_downloadable_apache_mirrors, $mirror
push @not_yet_downloadable_apache_mirrors, $response->request->uri unless (200 == $agent->get($mirror)->code);
unless (200 == $response->code); print ".";
} }
print "\n";
return @not_yet_downloadable_apache_mirrors; return @not_yet_downloadable_apache_mirrors;
} }