Skip to content

Commit

Permalink
Merge pull request #48 from metacpan/mickey/snapshot
Browse files Browse the repository at this point in the history
dev env updates
  • Loading branch information
mickeyn authored Oct 27, 2024
2 parents e965bc6 + dc2694d commit 80cdeec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
42 changes: 22 additions & 20 deletions bin/snapshot.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,42 @@
use HTTP::Tiny ();
use Getopt::Long;
use Sys::Hostname qw< hostname >;
use Try::Tiny;

use MetaCPAN::Logger qw< :log :dlog >;

use MetaCPAN::ES;
use MetaCPAN::Ingest qw< are_you_sure >;
use MetaCPAN::Ingest qw<
are_you_sure
config
is_dev
>;

# setup
my $hostname = hostname();
my $mode = $hostname =~ /dev/ ? 'testing' : 'production';
my $config = config();
my $mode = is_dev() ? 'testing' : 'production';
my $bucket = "mc-${mode}-backups"; # So we don't break production
my $repository_name = 'our_backups';

#my $es = MetaCPAN::ES->new( type => "distribution" );
#my $bulk = $es->bulk();
my $aws_key = $config->{es_aws_s3_access_key};
die "es_aws_s3_access_key not in config" unless $aws_key;

my $aws_secret = $config->{es_aws_s3_secret};
die "es_aws_s3_secret not in config" unless $aws_secret;

my $http_client = HTTP::Tiny->new(
default_headers => { 'Accept' => 'application/json' },
timeout => 120, # list can be slow
);

# args
my (
$date_format, $indices, $list, $purge_old, $restore,
$setup, $snap, $snap_name, $snap_stub
);
my $host = MetaCPAN::Server::Config::config()->{elasticsearch_servers};

my $host = $config->{es_node};

GetOptions(
"list" => \$list,
"date_format=s" => \$date_format,
Expand All @@ -45,20 +60,7 @@
# Note: can take wild cards https://www.elastic.co/guide/en/elasticsearch/reference/2.4/multi-index.html
$indices //= '*';

my $config = {}; ## TODO ( use MetaCPAN::Server::Config (); ??? )

my $aws_key = $config->{es_aws_s3_access_key};
my $aws_secret = $config->{es_aws_s3_secret};

my $http_client = HTTP::Tiny->new(
default_headers => { 'Accept' => 'application/json' },
timeout => 120, # list can be slow
);

# run
die "es_aws_s3_access_key not in config" unless $aws_key;
die "es_aws_s3_secret not in config" unless $aws_secret;

run_list_snaps() if $list;
run_setup() if $setup;
run_snapshot() if $snap;
Expand Down Expand Up @@ -205,7 +207,7 @@ ( $method, $path, $data )
Dlog_error {"Error response: $_"} $resp_json;
}
catch {
log_error { 'Error msg: ' . $response->{content} }
log_error { 'Error msg: ' . $response->{content} };
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ requires 'CPAN::DistnameInfo', '0.12';
requires 'Cpanel::JSON::XS';
requires 'Data::Printer';
requires 'DateTime';
requires 'DateTime::Format::ISO8601';
requires 'Data::Printer';
requires 'DBI';
requires 'Digest::SHA';
Expand Down Expand Up @@ -37,7 +38,7 @@ requires 'XML::Simple';

requires 'MetaCPAN::Common',
git => 'https://github.com/metacpan/MetaCPAN-Common',
ref => '48274b9cb890d7f76a8ba6e2fce78348ca1165ca';
ref => '0e5c2852178a47e98db291f613da2b96aca85f64';

on test => sub {
requires 'Code::TidyAll', '>= 0.74';
Expand Down
8 changes: 7 additions & 1 deletion lib/MetaCPAN/Ingest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use Sub::Exporter -setup => {
fix_version
handle_error
home
is_dev
minion
numify_version
read_00whois
Expand All @@ -55,7 +56,7 @@ my $config //= do {
};
$config->init_logger;

sub config () {$config}
sub config () { $config->config(); }

sub are_you_sure ( $msg, $force=0 ) {
return 1 if $force;
Expand Down Expand Up @@ -187,6 +188,11 @@ sub home () {
return $stdout;
}

# TODO: there must be a better way
sub is_dev () {
return $ENV{PLACK_ENV} =~ /dev/;
}

sub minion () {
require 'Mojo::Server';
return Mojo::Server->new->build_app('MetaCPAN::API')->minion;
Expand Down

0 comments on commit 80cdeec

Please sign in to comment.