Skip to content

Commit dc2694d

Browse files
committed
dev env updates
1 parent 2dcf324 commit dc2694d

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

bin/snapshot.pl

+23-21
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,48 @@
22
use warnings;
33
use v5.36;
44

5-
use Cpanel::JSON::XS qw< decode_json encode_json >;
5+
use Cpanel::JSON::XS qw< decode_json encode_json >;
66
use DateTime ();
77
use DateTime::Format::ISO8601 ();
88
use HTTP::Tiny ();
99
use Getopt::Long;
1010
use Sys::Hostname qw< hostname >;
11+
use Try::Tiny;
1112

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

1415
use MetaCPAN::ES;
15-
use MetaCPAN::Ingest qw< are_you_sure >;
16+
use MetaCPAN::Ingest qw<
17+
are_you_sure
18+
config
19+
is_dev
20+
>;
1621

1722
# setup
18-
my $hostname = hostname();
19-
my $mode = $hostname =~ /dev/ ? 'testing' : 'production';
23+
my $config = config();
24+
my $mode = is_dev() ? 'testing' : 'production';
2025
my $bucket = "mc-${mode}-backups"; # So we don't break production
2126
my $repository_name = 'our_backups';
2227

23-
#my $es = MetaCPAN::ES->new( type => "distribution" );
24-
#my $bulk = $es->bulk();
28+
my $aws_key = $config->{es_aws_s3_access_key};
29+
die "es_aws_s3_access_key not in config" unless $aws_key;
30+
31+
my $aws_secret = $config->{es_aws_s3_secret};
32+
die "es_aws_s3_secret not in config" unless $aws_secret;
33+
34+
my $http_client = HTTP::Tiny->new(
35+
default_headers => { 'Accept' => 'application/json' },
36+
timeout => 120, # list can be slow
37+
);
2538

2639
# args
2740
my (
2841
$date_format, $indices, $list, $purge_old, $restore,
2942
$setup, $snap, $snap_name, $snap_stub
3043
);
31-
my $host = MetaCPAN::Server::Config::config()->{elasticsearch_servers};
44+
45+
my $host = $config->{es_node};
46+
3247
GetOptions(
3348
"list" => \$list,
3449
"date_format=s" => \$date_format,
@@ -45,20 +60,7 @@
4560
# Note: can take wild cards https://www.elastic.co/guide/en/elasticsearch/reference/2.4/multi-index.html
4661
$indices //= '*';
4762

48-
my $config = {}; ## TODO ( use MetaCPAN::Server::Config (); ??? )
49-
50-
my $aws_key = $config->{es_aws_s3_access_key};
51-
my $aws_secret = $config->{es_aws_s3_secret};
52-
53-
my $http_client = HTTP::Tiny->new(
54-
default_headers => { 'Accept' => 'application/json' },
55-
timeout => 120, # list can be slow
56-
);
57-
5863
# run
59-
die "es_aws_s3_access_key not in config" unless $aws_key;
60-
die "es_aws_s3_secret not in config" unless $aws_secret;
61-
6264
run_list_snaps() if $list;
6365
run_setup() if $setup;
6466
run_snapshot() if $snap;
@@ -205,7 +207,7 @@ ( $method, $path, $data )
205207
Dlog_error {"Error response: $_"} $resp_json;
206208
}
207209
catch {
208-
log_error { 'Error msg: ' . $response->{content} }
210+
log_error { 'Error msg: ' . $response->{content} };
209211
}
210212
return 0;
211213
}

cpanfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ requires 'CPAN::DistnameInfo', '0.12';
66
requires 'Cpanel::JSON::XS';
77
requires 'Data::Printer';
88
requires 'DateTime';
9+
requires 'DateTime::Format::ISO8601';
910
requires 'Data::Printer';
1011
requires 'DBI';
1112
requires 'Digest::SHA';
@@ -37,7 +38,7 @@ requires 'XML::Simple';
3738

3839
requires 'MetaCPAN::Common',
3940
git => 'https://github.com/metacpan/MetaCPAN-Common',
40-
ref => '48274b9cb890d7f76a8ba6e2fce78348ca1165ca';
41+
ref => '0e5c2852178a47e98db291f613da2b96aca85f64';
4142

4243
on test => sub {
4344
requires 'Code::TidyAll', '>= 0.74';

lib/MetaCPAN/Ingest.pm

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use Sub::Exporter -setup => {
3232
fix_version
3333
handle_error
3434
home
35+
is_dev
3536
minion
3637
numify_version
3738
read_00whois
@@ -55,7 +56,7 @@ my $config //= do {
5556
};
5657
$config->init_logger;
5758

58-
sub config () {$config}
59+
sub config () { $config->config(); }
5960

6061
sub are_you_sure ( $msg, $force=0 ) {
6162
return 1 if $force;
@@ -187,6 +188,11 @@ sub home () {
187188
return $stdout;
188189
}
189190

191+
# TODO: there must be a better way
192+
sub is_dev () {
193+
return $ENV{PLACK_ENV} =~ /dev/;
194+
}
195+
190196
sub minion () {
191197
require 'Mojo::Server';
192198
return Mojo::Server->new->build_app('MetaCPAN::API')->minion;

0 commit comments

Comments
 (0)