File Coverage

blib/lib/HPC/Runner/Command/stats/Logger/JSON/Summary.pm
Criterion Covered Total %
statement 9 84 10.7
branch 0 12 0.0
condition 0 6 0.0
subroutine 3 15 20.0
pod 1 8 12.5
total 13 125 10.4


line stmt bran cond sub pod time code
1             package HPC::Runner::Command::stats::Logger::JSON::Summary;
2 1     1   857 use Moose::Role;
  1         3  
  1         10  
3              
4 1     1   4910 use JSON;
  1         2  
  1         13  
5 1     1   123 use Try::Tiny;
  1         3  
  1         678  
6              
7             ##This is probably mostly the same across plugins
8             sub iter_tasks_summary {
9 0     0 0   my $self = shift;
10 0           my $submission_id = shift;
11 0           my $jobname = shift;
12              
13 0           my $running = $self->count_running_tasks( $submission_id, $jobname );
14 0           my $success = $self->count_successful_tasks( $submission_id, $jobname );
15 0           my $fail = $self->count_failed_tasks( $submission_id, $jobname );
16 0           my $complete = $success + $fail;
17              
18 0           $self->task_data->{$jobname} = {
19             complete => $complete,
20             success => $success,
21             fail => $fail,
22             running => $running
23             };
24             }
25              
26             sub count_running_tasks {
27 0     0 0   my $self = shift;
28 0           my $submission_id = shift;
29 0           my $jobname = shift;
30              
31 0           my $basename = $self->data_tar->basename('.tar.gz');
32 0           my $running_file =
33             File::Spec->catdir( $basename, $jobname, 'running.json' );
34              
35 0 0         if ( $self->archive->contains_file($running_file) ) {
36 0           my $running_json = $self->archive->get_content($running_file);
37             ##TODO Add in some error checking
38 0           my $running;
39             try {
40 0     0     $running = decode_json($running_json);
41             }
42             catch {
43 0     0     $running = {};
44 0           };
45 0           my @keys = keys %{$running};
  0            
46 0           return scalar @keys;
47             }
48             else {
49 0           return 0;
50             }
51             }
52              
53             sub get_running_tasks {
54 0     0 0   my $self = shift;
55 0           my $submission_id = shift;
56 0           my $jobname = shift;
57              
58 0           my $basename = $self->data_tar->basename('.tar.gz');
59 0           my $running_file =
60             File::Spec->catdir( $basename, $jobname, 'running.json' );
61              
62 0 0         if ( $self->archive->contains_file($running_file) ) {
63 0           my $running_json = $self->archive->get_content($running_file);
64             ##TODO Add in some error checking
65 0           my $running = decode_json($running_json);
66 0           return $running;
67             }
68             else {
69 0           return {};
70             }
71              
72             }
73              
74             sub get_completed_tasks {
75 0     0 0   my $self = shift;
76 0           my $submission_id = shift;
77 0           my $jobname = shift;
78              
79 0           my $basename = $self->data_tar->basename('.tar.gz');
80 0           my $complete_file =
81             File::Spec->catdir( $basename, $jobname, 'complete.json' );
82              
83 0 0         if ( $self->archive->contains_file($complete_file) ) {
84 0           my $complete_json = $self->archive->get_content($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     0 0   my $self = shift;
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     0 0   my $self = shift;
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     0 1   my $self = shift;
119 0           my $jobname = shift;
120 0           my $success = shift;
121              
122 0           my $basename = $self->data_tar->basename('.tar.gz');
123 0           my $complete_file =
124             File::Spec->catdir( $basename, $jobname, 'complete.json' );
125              
126 0 0         if ( $self->archive->contains_file($complete_file) ) {
127 0           my $complete_json = $self->archive->get_content($complete_file);
128 0           my $complete;
129             try {
130 0     0     $complete = decode_json($complete_json);
131             }
132             catch {
133 0     0     $complete = {};
134 0           };
135             ##TODO Add in some error checking
136 0           return $self->look_for_exit_code( $complete, $success );
137             }
138             else {
139 0           return 0;
140             }
141             }
142              
143             sub look_for_exit_code {
144 0     0 0   my $self = shift;
145 0           my $complete = shift;
146 0           my $success = shift;
147              
148 0           my $task_count = 0;
149 0           foreach my $task ( keys %{$complete} ) {
  0            
150 0           my $task_data = $complete->{$task};
151              
152 0 0 0       if ( $success && $task_data->{exit_code} == 0 ) {
    0 0        
153 0           $task_count++;
154             }
155             elsif ( !$success && $task_data->{exit_code} != 0 ) {
156 0           $task_count++;
157             }
158             }
159              
160 0           return $task_count;
161             }
162              
163             1;