blib/lib/TAP/Parser/SourceHandler/Worker/PBS.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 96 CC 7 SCAR 24.1
CC
7
Cov
0%
get_active_workers
30.0
load_options
6.0
END
6.0
CRAP 11.2
1 package TAP::Parser::SourceHandler::Worker::PBS;
2  
3 use strict;
4 use Getopt::Long;
5 use Carp;
6 use vars (qw($VERSION @ISA));
7  
8 use TAP::Parser::IteratorFactory ();
9 use TAP::Parser::SourceHandler::Worker ();
10 @ISA = 'TAP::Parser::SourceHandler::Worker';
11  
12 TAP::Parser::IteratorFactory->register_handler(__PACKAGE__);
13  
14 =head1 NAME
15  
16 TAP::Parser::SourceHandler::Worker::PBS - Stream TAP from an L<IO::Handle> or a GLOB.
17  
18 =head1 VERSION
19  
20 Version 0.05
21  
22 =cut
23  
24 $VERSION = '0.05';
25  
26 use constant iterator_class => 'TAP::Parser::Iterator::Worker::PBS';
27  
28 =head3 C<@hosts>
29  
30 Class static variable to keep track of hosts.
31  
32 =cut
33  
34 my %pbs_args;
35  
36 =head3 C<get_active_workers>
37
38 my @active_workers = $class->get_active_workers;
39  
40 Returns list of active workers.
41  
42 =cut
43  
44 sub get_active_workers {
45 my $class = shift;
46  
47 my @workers = $class->SUPER::get_active_workers;
48  
49 return unless (@workers);
50 my @active;
51 for my $worker (@workers) {
52 if ( $worker->{pbs_job_id} ) {
53 my @info = `qstat $worker->{pbs_job_id}`;
54 unless ( $info[2] && $info[2] =~ /\s+(Q|R)\s+/ ) {
55 $worker = undef;
56 next;
57 }
58 }
59 push @active, $worker if ($worker);
60 }
61 return @active;
62 }
63  
64 =head3 C<load_options>
65
66 Setup the worker specific options.
67  
68 my @active_workers = $class->load_options($app_prove_object, \@ARGV);
69  
70 Returns boolean.
71  
72 =cut
73  
74 sub load_options {
75 my $class = shift;
76 my ( $app, $args ) = @_;
77 croak 'parent failed to load options.' unless($class->SUPER::load_options(@_));
78 {
79 local @ARGV = @$args;
80 Getopt::Long::Configure(qw(no_ignore_case bundling pass_through));
81 my %options;
82 for my $arg (
83 qw(server
84 wd name script tracer host nodes ppn account
85 partition queue begint ofile efile tfile pri mem pmem vmem pvmem cput
86 pcput wallt nice pbsid cmd prev next depend stagein stageout vars
87 shell maillist mailopt)
88 )
89 {
90 $options{$arg . '=s'} = \$pbs_args{$arg};
91 }
92  
93 # Don't add coderefs to GetOptions
94 GetOptions(%options)
95 or croak('Unable to continue');
96 }
97 return 1;
98 }
99  
100 =head3 C<get_args>
101  
102 Get PBS arguments.
103  
104 Returns argument hash
105  
106 =cut
107  
108 sub get_args {
109 return (%pbs_args);
110 }
111  
112 END {
113 for my $worker ( __PACKAGE__->workers ) {
114 next unless ( $worker && $worker->{pbs_job_id} );
115 my $command = 'qdel ' . $worker->{pbs_job_id};
116 print join "\n", map { '#' . $_ } split /\n/, `$command`;
117 print "\n";
118 }
119 }
120  
121 1;
122  
123 __END__