Pluggable/Status.pm

filter: Statementstmt 28.0% 21 / 75 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 18.6% 27 / 145 CC 29 SCAR 65.5
CC
29
Cov
16%
_update_status
870.0
_initialise_status
2.0
BEGIN
1.0
CRAP 701.1
↑ Summary Pluggable/Config.pm »
1 package Schedule::Pluggable::Status;
2 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp qw/ carp /;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use POSIX qw/ strftime /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $Data::Dumper::Sortkeys = 1;
9  
10 1 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 sub _initialise_status {
19 0 ▶ my $self = shift;
Subroutine _initialise_status: not called CC=1 SCAR=6.9
20 return {
21 0 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 sub _update_status {
36 0 ▶ my $self = shift;
Subroutine _update_status: not called CC=29 SCAR=67.7
37 0 my $no = 1;
38 0 my ($key, $params) = @_;
39 0 my $status = $self->_get_status();
40 my $job_name = $key->{name} ? $key->{name}
41 0 ▶ : $status->{Ids}{$key->{id}};
Branch: 1 branch
BranchTrueFalseTotal
$key->{'name'} ? : 0 0 0
42 # warn Data::Dumper->Dump([$key, $params, $status->{Ids}],[qw/$key $params $status->{Ids}/]) unless $job_name;
43 0 ▶ $job_name ||= "Job".$key->{id};
Condition0%0/2
$job_name ||= 'Job' . $key->{"id"}
l!l
00
MC/DC0%0/1
$job_name ||= 'Job' . $key->{"id"}
$job_name
Truth table0%0/2
A
A= $job_name
Aresult
11
00
44 0 ▶ return if $job_name eq 'MonitorJobs';
Branch: 1 branch
BranchTrueFalseTotal
if $job_name eq "MonitorJobs" 0 0 0
45 0 foreach my $p (keys %{ $params } ) {
46 0 ▶ $status->{Ids}{$params->{$p}} = $job_name if $p eq "Id";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Id" 0 0 0
47 0 ▶ $status->{Queued}{$job_name} = $params->{$p} if $p eq "Queued";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Queued" 0 0 0
48 0 ▶ $status->{Pids}{$job_name} = $params->{$p} if $p eq "Pid";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Pid" 0 0 0
49 0 ▶ $status->{TotalQueued}++ if $p eq "Id";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "Id" 0 0 0
50 0 ▶ $status->{TotalStarted}++ if $p eq "timestarted";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timestarted" 0 0 0
51 0 ▶ $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" 0 0 0
52 0 ▶ $status->{TotalFinished}++ if $p eq "timefinished";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timefinished" 0 0 0
53 # print Data::Dumper->Dump([$status->{Running}], [qw/$status->{Running}/]);
54 0 ▶ delete $status->{Running}{$job_name} if $p eq "timefinished";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timefinished" 0 0 0
55 0 ▶ delete $status->{Queued}{$job_name} if $p eq "timestarted";
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "timestarted" 0 0 0
56 # print Data::Dumper->Dump([$status->{Running}], [qw/$status->{Running}/]);
57 0 ▶ if (ref $params->{$p} eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params->{$p} eq 'ARRAY') { } 0 0 0
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 0 $status->{Jobs}{$job_name}{$p} = $params->{$p};
63 }
64 }
65  
66 0 my @jobs_to_queue = ();
67 0 ▶ if (defined($params->{status})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"status"}) 0 0 0
68 0 ▶ if ($params->{status} != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'status'} != 0) { } 0 0 0
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 0 $status->{TotalSucceeded}++;
77 0 my @jobs = keys %{ $status->{Jobs} };
78 0 JOB: foreach my $job (@jobs) {
79 0 ▶ next JOB if $job eq $job_name;
Branch: 1 branch
BranchTrueFalseTotal
if $job eq $job_name 0 0 0
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 0 $status->{LastUpdate} = strftime('%d/%m/%Y %H:%M:%S', localtime(time()));
97 0 $self->_set_status($status);
98 0 ▶ if (scalar(@jobs_to_queue) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @jobs_to_queue > 0) 0 0 0
99 0 $self->_queue_jobs(@jobs_to_queue);
100 }
101 0 ▶ if ($status->{TotalFailed} > 0 or $status->{TotalFinished} >= $status->{TotalJobs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}) 0 0 0
Condition0%0/3
$status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}
$status->{"TotalFailed"} > 0 $status->{"TotalFinished"} >= $status->{"TotalJobs"}
Truth table0%0/3
A or B
A= $status->{"TotalFailed"} > 0B= $status->{"TotalFinished"} >= $status->{"TotalJobs"}
ABresult
1X1
011
000
102 0 system("touch ".$status->{EndOfScheduleFile});
103 }
104 }
105 1 1;
106 __END__
107  
108 =head1 NAME
109  
110 Schedule::Pluggable::Status - Moose Role to provide methods to update the status when events occur
111  
112 =head1 DESCRIPTION
113  
114 Moose Role to add method to Schedule::Pluggable to update the status when events occur - not runnable on it's own
115  
116 =head1 METHODS
117  
118 No public methods
119  
120 =cut
121  
↑ Summary Pluggable/Config.pm »