Skip to content

Commit

Permalink
Merge pull request #444 from CPAN-API/oalders/queue
Browse files Browse the repository at this point in the history
Add CLI for adding releases to queue
  • Loading branch information
ranguard committed Apr 6, 2016
2 parents fab32bc + a5e3dee commit 480d931
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 8 deletions.
Empty file modified bin/queue.pl 100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions cpanfile
Expand Up @@ -117,6 +117,7 @@ requires 'Parse::CPAN::Packages::Fast', '0.09';
requires 'Parse::CSV', '2.04';
requires 'Parse::PMFile', '0.29';
requires 'Path::Class', '0.36';
requires 'Path::Iterator::Rule', '>=1.011';
requires 'Path::Class::File';
requires 'PerlIO::gzip';
requires 'Pithub', '0.01033';
Expand Down
20 changes: 20 additions & 0 deletions cpanfile.snapshot
Expand Up @@ -6389,6 +6389,26 @@ DISTRIBUTIONS
strict 0
utf8 0
warnings 0
Path-Iterator-Rule-1.011
pathname: D/DA/DAGOLDEN/Path-Iterator-Rule-1.011.tar.gz
provides:
PIR 1.011
Path::Iterator::Rule 1.011
requirements:
Carp 0
ExtUtils::MakeMaker 6.17
File::Basename 0
File::Spec 0
List::Util 0
Number::Compare 0.02
Scalar::Util 0
Text::Glob 0
Try::Tiny 0
perl 5.010
re 0
strict 0
warnings 0
warnings::register 0
Path-Tiny-0.054
pathname: D/DA/DAGOLDEN/Path-Tiny-0.054.tar.gz
provides:
Expand Down
2 changes: 1 addition & 1 deletion git/hooks/pre-commit
Expand Up @@ -6,4 +6,4 @@ use warnings;
use lib 'local/lib/perl5';

use Code::TidyAll::Git::Precommit;
Code::TidyAll::Git::Precommit->check();
Code::TidyAll::Git::Precommit->check( no_stash => 1 );
4 changes: 4 additions & 0 deletions lib/MetaCPAN/Queue.pm
Expand Up @@ -8,6 +8,9 @@ queue.
# On vagrant VM
./bin/run morbo bin/queue.pl
# Display information on jobs in queue
./bin/run bin/queue.pl minion job
=cut

use Mojo::Base 'Mojolicious';
Expand Down Expand Up @@ -39,6 +42,7 @@ sub startup {
}
catch {
warn $_;
$job->fail( { message => $_ } );
};
}
);
Expand Down
65 changes: 65 additions & 0 deletions lib/MetaCPAN/Script/Queue.pm
@@ -0,0 +1,65 @@
package MetaCPAN::Script::Queue;

use strict;
use warnings;

use MetaCPAN::Queue ();
use MetaCPAN::Types qw( Dir File );
use Moose;
use Path::Iterator::Rule ();

has dir => (
is => 'ro',
isa => Dir,
predicate => '_has_dir',
coerce => 1,
);

has file => (
is => 'ro',
isa => File,
predicate => '_has_file',
coerce => 1,
);

has _minion => (
is => 'ro',
isa => 'Minion',
lazy => 1,
handles => { _add_to_queue => 'enqueue', stats => 'stats', },
default => sub { MetaCPAN::Queue->new->minion },
);

with 'MetaCPAN::Role::Script', 'MooseX::Getopt';

sub run {
my $self = shift;

if ( $self->_has_dir ) {
my $rule = Path::Iterator::Rule->new;
$rule->name(qr{\.(tgz|tbz|tar[\._-]gz|tar\.bz2|tar\.Z|zip|7z)\z});

my $next = $rule->iter( $self->dir );
while ( defined( my $file = $next->() ) ) {
$self->_add_to_queue( index_release => [$file] );
}
}

if ( $self->_has_file ) {
$self->_add_to_queue( index_release => [ $self->file->stringify ] );
}
}

__PACKAGE__->meta->make_immutable;
1;
__END__
=head1 SYNOPSIS
bin/metacpan queue --file https://cpan.metacpan.org/authors/id/O/OA/OALDERS/HTML-Restrict-2.2.2.tar.gz
bin/metacpan queue --dir /home/metacpan/CPAN/
bin/metacpan queue --dir /home/metacpan/CPAN/authors/id
bin/metacpan queue --dir /home/metacpan/CPAN/authors/id/R/RW/RWSTAUNER
bin/metacpan queue --file /home/metacpan/CPAN/authors/id/R/RW/RWSTAUNER/Timer-Simple-1.006.tar.gz
=cut
13 changes: 6 additions & 7 deletions lib/MetaCPAN/Script/Runner.pm
Expand Up @@ -4,7 +4,6 @@ use strict;
use warnings;

use Config::JFDI;
use FindBin;
use File::Path ();
use Hash::Merge::Simple qw(merge);
use IO::Interactive qw(is_interactive);
Expand Down Expand Up @@ -34,20 +33,20 @@ sub run {

sub build_config {
my $config = Config::JFDI->new(
name => "metacpan",
path => "$FindBin::RealBin/../etc"
name => 'metacpan',
path => 'etc'
)->get;
if ( $ENV{HARNESS_ACTIVE} ) {
my $tconf = Config::JFDI->new(
name => "metacpan",
file => "$FindBin::RealBin/../etc/metacpan_testing.pl"
name => 'metacpan',
file => 'etc/metacpan_testing.pl'
)->get;
$config = merge $config, $tconf;
}
elsif ( is_interactive() ) {
my $iconf = Config::JFDI->new(
name => "metacpan",
file => "$FindBin::RealBin/../etc/metacpan_interactive.pl"
name => 'metacpan',
file => 'etc/metacpan_interactive.pl'
)->get;
$config = merge $config, $iconf;
}
Expand Down
18 changes: 18 additions & 0 deletions t/script/queue.t
@@ -0,0 +1,18 @@
use strict;
use warnings;

use Test::More;

use MetaCPAN::Script::Runner;
use MetaCPAN::Script::Queue;

my $config = MetaCPAN::Script::Runner::build_config;
local @ARGV = ( '--dir', $config->{cpan} );

my $queue = MetaCPAN::Script::Queue->new_with_options($config);
$queue->run;

is( $queue->stats->{inactive_jobs},
52, '52 files added to queue for indexing' );

done_testing();

0 comments on commit 480d931

Please sign in to comment.