blib/lib/HPC/Runner/Command/stats/Logger/JSON/Summary.pm

filter: Statementstmt 18.3% 16 / 87 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 29.4% 5 / 17 Podpod 12.5% 1 / 8 totaltotal 16.4% 22 / 134 CC 10 SCAR 25.1
CC
10
Cov
15%
look_for_exit_code
42.0
count_running_tasks
6.0
get_running_tasks
6.0
CRAP 12.3
« blib/lib/HPC/Runner/Command/execute_array.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Log.pm »
1 package HPC::Runner::Command::stats::Logger::JSON::Summary;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 ##This is probably mostly the same across plugins
11 sub iter_tasks_summary {
12 0 ▶ my $self = shift;
Subroutine iter_tasks_summary: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my $submission_id = shift;
14 0 my $jobname = shift;
15  
16 0 my $running = $self->count_running_tasks( $submission_id, $jobname );
17 0 my $success = $self->count_successful_tasks( $submission_id, $jobname );
18 0 my $fail = $self->count_failed_tasks( $submission_id, $jobname );
19 0 my $complete = $success + $fail;
20  
21 0 $self->task_data->{$jobname} = {
22 complete => $complete,
23 success => $success,
24 fail => $fail,
25 running => $running
26 };
27 }
28  
29 sub count_running_tasks {
30 0 ▶ my $self = shift;
Subroutine count_running_tasks: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my $submission_id = shift;
32 0 my $jobname = shift;
33  
34 0 my $running_file =
35 File::Spec->catdir( $self->data_dir, $jobname, 'running.json' );
36  
37 0 ▶ if ( -e $running_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $running_file) { } 0 0 0
38 0 my $running_json = read_file($running_file);
39 ##TODO Add in some error checking
40 0 my $running;
41 try {
42 0 ▶ $running = decode_json($running_json);
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 }
44 catch {
45 0 ▶ $running = {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 };
47 0 my @keys = keys %{$running};
48 0 return scalar @keys;
49 }
50 else {
51 0 return 0;
52 }
53 }
54  
55 sub get_running_tasks {
56 0 ▶ my $self = shift;
Subroutine get_running_tasks: not called CC=2 SCAR=17.9
Pod undocumented
57 0 my $submission_id = shift;
58 0 my $jobname = shift;
59  
60 0 my $running_file =
61 File::Spec->catdir( $self->data_dir, $jobname, 'running.json' );
62  
63 0 ▶ if ( -e $running_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $running_file) { } 0 0 0
64 0 my $running_json = read_file($running_file);
65 ##TODO Add in some error checking
66 0 my $running = decode_json($running_json);
67 0 return $running;
68 }
69 else {
70 0 return {};
71 }
72  
73 }
74  
75 sub get_completed_tasks {
76 0 ▶ my $self = shift;
Subroutine get_completed_tasks: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my $submission_id = shift;
78 0 my $jobname = shift;
79  
80 0 my $complete_file =
81 File::Spec->catdir( $self->data_dir, $jobname, 'complete.json' );
82  
83 0 ▶ if ( -e $complete_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $complete_file) { } 0 0 0
84 0 my $complete_json = read_file($complete_file);
85 ##TODO Add in some error checking
86 0 my $complete = decode_json($complete_json);
87 0 return $complete;
88 }
89 else {
90 0 return {};
91 }
92  
93 }
94  
95 sub count_successful_tasks {
96 0 ▶ my $self = shift;
Subroutine count_successful_tasks: not called CC=1 SCAR=6.9
Pod undocumented
97 0 my $submission_id = shift;
98 0 my $jobname = shift;
99  
100 0 return $self->search_complete( $jobname, 1 );
101 }
102  
103 sub count_failed_tasks {
104 0 ▶ my $self = shift;
Subroutine count_failed_tasks: not called CC=1 SCAR=6.9
Pod undocumented
105 0 my $submission_id = shift;
106 0 my $jobname = shift;
107  
108 0 return $self->search_complete( $jobname, 0 );
109 }
110  
111 =head3 search_complete
112  
113 See which jobs completed successfully
114  
115 =cut
116  
117 sub search_complete {
118 0 ▶ my $self = shift;
Subroutine search_complete: not called CC=2 SCAR=17.9
Pod documented
119 0 my $jobname = shift;
120 0 my $success = shift;
121  
122 0 my $complete_file =
123 File::Spec->catdir( $self->data_dir, $jobname, 'complete.json' );
124  
125 0 ▶ if ( -e $complete_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $complete_file) { } 0 0 0
126 0 my $complete_json = read_file($complete_file);
127 0 my $complete;
128 try {
129 0 ▶ $complete = decode_json($complete_json);
Subroutine __ANON__: not called CC=1 SCAR=6.9
130 }
131 catch {
132 0 ▶ $complete = {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
133 0 };
134 ##TODO Add in some error checking
135 0 return $self->look_for_exit_code( $complete, $success );
136 }
137 else {
138 0 return 0;
139 }
140 }
141  
142 sub look_for_exit_code {
143 0 ▶ my $self = shift;
Subroutine look_for_exit_code: not called CC=6 SCAR=37.4
Pod undocumented
144 0 my $complete = shift;
145 0 my $success = shift;
146  
147 0 my $task_count = 0;
148 0 foreach my $task ( keys %{$complete} ) {
149 0 my $task_data = $complete->{$task};
150  
151 0 ▶ if ( $success && $task_data->{exit_code} == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($success and $task_data->{'exit_code'} == 0) { } 0 0 0
elsif (not $success and $task_data->{'exit_code'} != 0) { } 0 0 0
Condition0%0/3
$success and $task_data->{"exit_code"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$success and $task_data->{"exit_code"} == 0
$success $task_data->{"exit_code"} == 0
Truth table0%0/3
A and B
A= $successB= $task_data->{"exit_code"} == 0
ABresult
0X0
100
111
152 0 $task_count++;
153 }
154 ▶ elsif ( !$success && $task_data->{exit_code} != 0 ) {
Condition0%0/3
not $success and $task_data->{"exit_code"} != 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $success and $task_data->{"exit_code"} != 0
not $success $task_data->{"exit_code"} != 0
Truth table0%0/3
not(A) and B
A= not $successB= $task_data->{"exit_code"} != 0
ABresult
0X0
100
111
155 0 $task_count++;
156 }
157 }
158  
159 0 return $task_count;
160 }
161  
162 1 1;
« blib/lib/HPC/Runner/Command/execute_array.pm ↑ Summary blib/lib/HPC/Runner/Command/submit_jobs/Utils/Log.pm »