| 1 | package Bio::Roary::JobRunner::Parallel; | ||
| 2 | $Bio::Roary::JobRunner::Parallel::VERSION = '3.13.0'; | ||
| 3 | # ABSTRACT: Use GNU Parallel | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use File::Temp qw/ tempfile /; | ||
| 8 | use Log::Log4perl qw(:easy); | ||
| 9 | use File::Slurper 'write_text'; | ||
| 10 | use File::Temp qw/ tempfile /; | ||
| 11 | |||
| 12 | has 'commands_to_run' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | ||
| 13 | has 'cpus' => ( is => 'ro', isa => 'Int', default => 1 ); | ||
| 14 | has 'logger' => ( is => 'ro', lazy => 1, builder => '_build_logger'); | ||
| 15 | has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 ); | ||
| 16 | has 'memory_in_mb' => ( is => 'rw', isa => 'Int', default => '200' ); | ||
| 17 | |||
| 18 | sub run { | ||
| 19 | my ($self) = @_; | ||
| 20 | |||
| 21 | my($fh, $temp_command_filename) = tempfile(); | ||
| 22 | write_text($temp_command_filename, join("\n", @{ $self->commands_to_run }) ); | ||
| 23 | |||
| 24 | for my $command_to_run(@{ $self->commands_to_run }) | ||
| 25 | { | ||
| 26 | $self->logger->info($command_to_run); | ||
| 27 | } | ||
| 28 | my $parallel_command = "parallel --gnu -j ".$self->cpus." < ".$temp_command_filename ; | ||
| 29 | $self->logger->info($parallel_command ); | ||
| 30 | |||
| 31 | system($parallel_command); | ||
| 32 | 1; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub _construct_dependancy_params | ||
| 36 | { | ||
| 37 | my ($self) = @_; | ||
| 38 | return ''; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub submit_dependancy_job { | ||
| 42 | my ( $self,$command_to_run) = @_; | ||
| 43 | $self->logger->info($command_to_run); | ||
| 44 | system($command_to_run ); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub _build_logger | ||
| 48 | { | ||
| 49 | my ($self) = @_; | ||
| 50 | my $level = $ERROR; | ||
| 51 | if($self->verbose) | ||
| 52 | { | ||
| 53 | $level = $DEBUG; | ||
| 54 | } | ||
| 55 | Log::Log4perl->easy_init($level); | ||
| 56 | my $logger = get_logger(); | ||
| 57 | return $logger; | ||
| 58 | } | ||
| 59 | |||
| 60 | no Moose; | ||
| 61 | __PACKAGE__->meta->make_immutable; | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ |