-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from metacpan/mickey/mirrors
Added mirrors script
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use strict; | ||
use warnings; | ||
use v5.36; | ||
|
||
use Getopt::Long; | ||
use MetaCPAN::Logger qw< :log :dlog >; | ||
use Cpanel::JSON::XS (); | ||
|
||
use MetaCPAN::ES; | ||
use MetaCPAN::Ingest qw< cpan_dir >; | ||
|
||
# args | ||
my ( $distribution, $files_only, $undo ); | ||
GetOptions( | ||
"distribution=s" => \$distribution, | ||
"files_only" => \$files_only, | ||
"undo" => \$undo, | ||
); | ||
|
||
# setup | ||
my $cpan = cpan_dir(); | ||
my $es = MetaCPAN::ES->new( type => "mirror" ); | ||
|
||
|
||
index_mirrors(); | ||
|
||
$es->index_refresh; | ||
|
||
# TODO: | ||
# cdn_purge_now( { keys => ['MIRRORS'], } ); | ||
|
||
log_info {"done"}; | ||
|
||
### | ||
|
||
sub index_mirrors () { | ||
log_info { 'Getting mirrors.json file from ' . $cpan }; | ||
|
||
my $json = $cpan->child( 'indices', 'mirrors.json' )->slurp; | ||
|
||
# Clear out everything in the index | ||
# so don't end up with old mirrors | ||
$es->clear_type; | ||
|
||
my $mirrors = Cpanel::JSON::XS::decode_json($json); | ||
foreach my $mirror (@$mirrors) { | ||
$mirror->{location} = { | ||
lon => delete $mirror->{longitude}, | ||
lat => delete $mirror->{latitude} | ||
}; | ||
|
||
#Dlog_trace {"Indexing $_"} $mirror; | ||
log_debug {sprintf("Indexing %s", $mirror->{name})}; | ||
|
||
my @doc = | ||
map { $_ => $mirror->{$_} } | ||
grep { defined $mirror->{$_} } | ||
keys %$mirror; | ||
|
||
$es->index( body => { @doc } ); | ||
} | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=pod | ||
=head1 SYNOPSIS | ||
$ bin/mirrors.pl | ||
=head1 SOURCE | ||
L<http://www.cpan.org/indices/mirrors.json> | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters