Skip to content

Commit 480d931

Browse files
committed
Merge pull request metacpan#444 from CPAN-API/oalders/queue
Add CLI for adding releases to queue
2 parents fab32bc + a5e3dee commit 480d931

File tree

8 files changed

+115
-8
lines changed

8 files changed

+115
-8
lines changed

bin/queue.pl

100644100755
File mode changed.

cpanfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ requires 'Parse::CPAN::Packages::Fast', '0.09';
117117
requires 'Parse::CSV', '2.04';
118118
requires 'Parse::PMFile', '0.29';
119119
requires 'Path::Class', '0.36';
120+
requires 'Path::Iterator::Rule', '>=1.011';
120121
requires 'Path::Class::File';
121122
requires 'PerlIO::gzip';
122123
requires 'Pithub', '0.01033';

cpanfile.snapshot

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6389,6 +6389,26 @@ DISTRIBUTIONS
63896389
strict 0
63906390
utf8 0
63916391
warnings 0
6392+
Path-Iterator-Rule-1.011
6393+
pathname: D/DA/DAGOLDEN/Path-Iterator-Rule-1.011.tar.gz
6394+
provides:
6395+
PIR 1.011
6396+
Path::Iterator::Rule 1.011
6397+
requirements:
6398+
Carp 0
6399+
ExtUtils::MakeMaker 6.17
6400+
File::Basename 0
6401+
File::Spec 0
6402+
List::Util 0
6403+
Number::Compare 0.02
6404+
Scalar::Util 0
6405+
Text::Glob 0
6406+
Try::Tiny 0
6407+
perl 5.010
6408+
re 0
6409+
strict 0
6410+
warnings 0
6411+
warnings::register 0
63926412
Path-Tiny-0.054
63936413
pathname: D/DA/DAGOLDEN/Path-Tiny-0.054.tar.gz
63946414
provides:

git/hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ use warnings;
66
use lib 'local/lib/perl5';
77

88
use Code::TidyAll::Git::Precommit;
9-
Code::TidyAll::Git::Precommit->check();
9+
Code::TidyAll::Git::Precommit->check( no_stash => 1 );

lib/MetaCPAN/Queue.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ queue.
88
# On vagrant VM
99
./bin/run morbo bin/queue.pl
1010
11+
# Display information on jobs in queue
12+
./bin/run bin/queue.pl minion job
13+
1114
=cut
1215

1316
use Mojo::Base 'Mojolicious';
@@ -39,6 +42,7 @@ sub startup {
3942
}
4043
catch {
4144
warn $_;
45+
$job->fail( { message => $_ } );
4246
};
4347
}
4448
);

lib/MetaCPAN/Script/Queue.pm

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package MetaCPAN::Script::Queue;
2+
3+
use strict;
4+
use warnings;
5+
6+
use MetaCPAN::Queue ();
7+
use MetaCPAN::Types qw( Dir File );
8+
use Moose;
9+
use Path::Iterator::Rule ();
10+
11+
has dir => (
12+
is => 'ro',
13+
isa => Dir,
14+
predicate => '_has_dir',
15+
coerce => 1,
16+
);
17+
18+
has file => (
19+
is => 'ro',
20+
isa => File,
21+
predicate => '_has_file',
22+
coerce => 1,
23+
);
24+
25+
has _minion => (
26+
is => 'ro',
27+
isa => 'Minion',
28+
lazy => 1,
29+
handles => { _add_to_queue => 'enqueue', stats => 'stats', },
30+
default => sub { MetaCPAN::Queue->new->minion },
31+
);
32+
33+
with 'MetaCPAN::Role::Script', 'MooseX::Getopt';
34+
35+
sub run {
36+
my $self = shift;
37+
38+
if ( $self->_has_dir ) {
39+
my $rule = Path::Iterator::Rule->new;
40+
$rule->name(qr{\.(tgz|tbz|tar[\._-]gz|tar\.bz2|tar\.Z|zip|7z)\z});
41+
42+
my $next = $rule->iter( $self->dir );
43+
while ( defined( my $file = $next->() ) ) {
44+
$self->_add_to_queue( index_release => [$file] );
45+
}
46+
}
47+
48+
if ( $self->_has_file ) {
49+
$self->_add_to_queue( index_release => [ $self->file->stringify ] );
50+
}
51+
}
52+
53+
__PACKAGE__->meta->make_immutable;
54+
1;
55+
__END__
56+
57+
=head1 SYNOPSIS
58+
59+
bin/metacpan queue --file https://cpan.metacpan.org/authors/id/O/OA/OALDERS/HTML-Restrict-2.2.2.tar.gz
60+
bin/metacpan queue --dir /home/metacpan/CPAN/
61+
bin/metacpan queue --dir /home/metacpan/CPAN/authors/id
62+
bin/metacpan queue --dir /home/metacpan/CPAN/authors/id/R/RW/RWSTAUNER
63+
bin/metacpan queue --file /home/metacpan/CPAN/authors/id/R/RW/RWSTAUNER/Timer-Simple-1.006.tar.gz
64+
65+
=cut

lib/MetaCPAN/Script/Runner.pm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use strict;
44
use warnings;
55

66
use Config::JFDI;
7-
use FindBin;
87
use File::Path ();
98
use Hash::Merge::Simple qw(merge);
109
use IO::Interactive qw(is_interactive);
@@ -34,20 +33,20 @@ sub run {
3433

3534
sub build_config {
3635
my $config = Config::JFDI->new(
37-
name => "metacpan",
38-
path => "$FindBin::RealBin/../etc"
36+
name => 'metacpan',
37+
path => 'etc'
3938
)->get;
4039
if ( $ENV{HARNESS_ACTIVE} ) {
4140
my $tconf = Config::JFDI->new(
42-
name => "metacpan",
43-
file => "$FindBin::RealBin/../etc/metacpan_testing.pl"
41+
name => 'metacpan',
42+
file => 'etc/metacpan_testing.pl'
4443
)->get;
4544
$config = merge $config, $tconf;
4645
}
4746
elsif ( is_interactive() ) {
4847
my $iconf = Config::JFDI->new(
49-
name => "metacpan",
50-
file => "$FindBin::RealBin/../etc/metacpan_interactive.pl"
48+
name => 'metacpan',
49+
file => 'etc/metacpan_interactive.pl'
5150
)->get;
5251
$config = merge $config, $iconf;
5352
}

t/script/queue.t

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
6+
use MetaCPAN::Script::Runner;
7+
use MetaCPAN::Script::Queue;
8+
9+
my $config = MetaCPAN::Script::Runner::build_config;
10+
local @ARGV = ( '--dir', $config->{cpan} );
11+
12+
my $queue = MetaCPAN::Script::Queue->new_with_options($config);
13+
$queue->run;
14+
15+
is( $queue->stats->{inactive_jobs},
16+
52, '52 files added to queue for indexing' );
17+
18+
done_testing();

0 commit comments

Comments
 (0)