Pluggable/Status.pm

filter: Statementstmt 74.6% 56 / 75 Branchbran 75.0% 30 / 40 Conditioncond 21.4% 3 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 67.5% 98 / 145 CC 29 SCAR 40.9
CC
29
Cov
69%
_update_status
74.2
BEGIN
1.0
BEGIN
1.0
CRAP 60.0
↑ Summary Pluggable/Config.pm »
1 package Schedule::Pluggable::Status;
2 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw/ carp /;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use POSIX qw/ strftime /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 $Data::Dumper::Sortkeys = 1;
9  
10 3 has status => ( is => 'rw',
11 isa => 'HashRef',
12 lazy => 1,
13 reader => '_get_status',
14 writer => '_set_status',
15 builder => '_initialise_status',
16 );
17  
18 1 ▶sub _initialise_status {
Subroutine _initialise_status: called CC=1 SCAR=0.0
19 1 my $self = shift;
20 return {
21 1 Jobs => {},
22 TotalJobs => 0,
23 TotalQueued => 0,
24 TotalStarted => 0,
25 TotalFinished => 0,
26 TotalSucceeded => 0,
27 TotalFailed => 0,
28 Groups => {},
29 Ready_to_Run => {},
30 Ids => {},
31 Pids => {},
32 };
33 }
34  
35 7 ▶sub _update_status {
Subroutine _update_status: called CC=29 SCAR=43.1
36 7 my $self = shift;
37 7 my $no = 1;
38 7 my ($key, $params) = @_;
39 7 my $status = $self->_get_status();
40 my $job_name = $key->{name} ? $key->{name}
41 7 ▶ : $status->{Ids}{$key->{id}};
Branch: 1 branch
BranchTrueFalseTotal
$key->{'name'} ? : 5 2 7
42 # warn Data::Dumper->Dump([$key, $params, $status->{Ids}],[qw/$key $params $status->{Ids}/]) unless $job_name;
43 7 ▶ $job_name ||= "Job".$key->{id};
Condition50%1/2
$job_name ||= 'Job' . $key->{"id"}
l!l
70
MC/DC0%0/1
$job_name ||= 'Job' . $key->{"id"}
$job_name
Truth table50%1/2
A
A= $job_name
Aresult
11
00
44 7 ▶ return if $job_name eq 'MonitorJobs';
Branch: 1 branch
BranchTrueFalseTotal
if $job_name eq "MonitorJobs" 3 4 7
45 4 foreach my $p (keys %{ $params } ) {
46 6 ▶ $status->{Ids}{$params->{$p}} = $job_name if $p eq "Id";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Id" 1 5 6
47 6 ▶ $status->{Queued}{$job_name} = $params->{$p} if $p eq "Queued";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Queued" 1 5 6
48 6 ▶ $status->{Pids}{$job_name} = $params->{$p} if $p eq "Pid";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Pid" 1 5 6
49 6 ▶ $status->{TotalQueued}++ if $p eq "Id";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Id" 1 5 6
50 6 ▶ $status->{TotalStarted}++ if $p eq "timestarted";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timestarted" 1 5 6
51 6 ▶ $status->{Running}{$job_name} = strftime('%d/%m/%Y %H:%M:%S', localtime(time())) if $p eq "timestarted";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timestarted" 1 5 6
52 6 ▶ $status->{TotalFinished}++ if $p eq "timefinished";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timefinished" 1 5 6
53 # print Data::Dumper->Dump([$status->{Running}], [qw/$status->{Running}/]);
54 6 ▶ delete $status->{Running}{$job_name} if $p eq "timefinished";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timefinished" 1 5 6
55 6 ▶ delete $status->{Queued}{$job_name} if $p eq "timestarted";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timestarted" 1 5 6
56 # print Data::Dumper->Dump([$status->{Running}], [qw/$status->{Running}/]);
57 6 ▶ if (ref $params->{$p} eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params->{$p} eq 'ARRAY') { } 0 6 6
58 0 ▶ $status->{Jobs}{$job_name}{$p} ||= [];
Condition0%0/2
$status->{"Jobs"}{$job_name}{$p} ||= []
l!l
00
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{$p} ||= []
$status->{"Jobs"}{$job_name}{$p}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{$p}
Aresult
11
00
59 0 push(@{ $status->{Jobs}{$job_name}{$p} }, @{ $params->{$p} });
60 }
61 else {
62 6 $status->{Jobs}{$job_name}{$p} = $params->{$p};
63 }
64 }
65  
66 4 my @jobs_to_queue = ();
67 4 ▶ if (defined($params->{status})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"status"}) 1 3 4
68 1 ▶ if ($params->{status} != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'status'} != 0) { } 0 1 1
69 0 $status->{TotalFailed}++;
70 0 ▶ $status->{Jobs}{$job_name}{stderr} ||= [ pop(@{ $status->{Jobs}{$job_name}{stdout} }) ];
Condition0%0/2
$status->{"Jobs"}{$job_name}{"stderr"} ||= [pop @{$$status{"Jobs"}{$job_name}{"stdout"};}]
l!l
00
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{"stderr"} ||= [pop @{$$status{"Jobs"}{$job_name}{"stdout"};}]
$status->{"Jobs"}{$job_name}{"stderr"}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{"stderr"}
Aresult
11
00
71 0 ▶ $status->{Jobs}{$job_name}{stderr} ||= [];
Condition0%0/2
$status->{"Jobs"}{$job_name}{"stderr"} ||= []
l!l
00
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{"stderr"} ||= []
$status->{"Jobs"}{$job_name}{"stderr"}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{"stderr"}
Aresult
11
00
72 $status->{Failed}{$job_name} = { status => $params->{status},
73 0 stderr => [ @{ $status->{Jobs}{$job_name}{stderr} } ] };
74 }
75 else {
76 1 $status->{TotalSucceeded}++;
77 1 my @jobs = keys %{ $status->{Jobs} };
78 1 JOB: foreach my $job (@jobs) {
79 1 ▶ next JOB if $job eq $job_name;
Branch: 1 branch
BranchTrueFalseTotal
if $job eq $job_name 1 0 1
80 0 ▶ if ($status->{Jobs}{$job}{prerequisites}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"Jobs"}{$job}{"prerequisites"}) 0 0 0
81 0 my %p = %{ $status->{Jobs}{$job}{prerequisites} };
82 0 ▶ if (exists ($p{$job_name} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p{$job_name}) 0 0 0
83 0 $status->{Jobs}{$job}{prerequisites}{$job_name} = strftime('%d/%m/%Y %H:%M:%S', localtime(time()));
84 0 $status->{Jobs}{$job}{ pending_prerequisites }--;
85 }
86 0 ▶ if (!defined($status->{Jobs}{$job}{timestarted}) and
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $status->{"Jobs"}{$job}{"timestarted"} and $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0) 0 0 0
Condition0%0/3
not defined $status->{"Jobs"}{$job}{"timestarted"} and $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $status->{"Jobs"}{$job}{"timestarted"} and $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
not defined $status->{"Jobs"}{$job}{"timestarted"} $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
Truth table0%0/3
not(A) and B
A= not defined $status->{"Jobs"}{$job}{"timestarted"}B= $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
ABresult
0X0
100
111
87 $status->{Jobs}{$job}{ pending_prerequisites } == 0) {
88  
89 0 push(@jobs_to_queue, {name => $job, command => $status->{Jobs}{$job}{command} });
90 }
91 #$self->queue_jobs($status->{Jobs}{$job}) if $status->{Jobs}{$job}{ pending_prerequisites } == 0;
92 }
93 }
94 }
95 }
96 4 $status->{LastUpdate} = strftime('%d/%m/%Y %H:%M:%S', localtime(time()));
97 4 $self->_set_status($status);
98 4 ▶ if (scalar(@jobs_to_queue) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @jobs_to_queue > 0) 0 4 4
99 0 $self->_queue_jobs(@jobs_to_queue);
100 }
101 4 ▶ if ($status->{TotalFailed} > 0 or $status->{TotalFinished} >= $status->{TotalJobs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}) 2 2 4
Condition66%2/3
$status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}
l!l&&r!l&&!r
022
MC/DC50%1/2
$status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}
$status->{"TotalFailed"} > 0 $status->{"TotalFinished"} >= $status->{"TotalJobs"}
Truth table66%2/3
A or B
A= $status->{"TotalFailed"} > 0B= $status->{"TotalFinished"} >= $status->{"TotalJobs"}
ABresult
1X1
011
000
102 2 system("touch ".$status->{EndOfScheduleFile});
103 }
104 }
105 3 1;
106 __END__
↑ Summary Pluggable/Config.pm »