Panoptes/JobInfo.pm untested

filter: Statementstmt 0.0% 0 / 118 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 145 CC 8 SCAR 35.5
CC
8
Cov
0%
rm_jobinfo
72.0
setup
2.0
teardown
2.0
CRAP 34.9
1 package Helios::Panoptes::JobInfo;
2
3 use 5.008;
4 use strict;
5 use warnings;
6 use base qw(Helios::Panoptes::Base);
7 use Data::Dumper;
8 use CGI::Application::Plugin::DBH qw(dbh_config dbh);
9
10 use Helios::Error;
11
12 our $VERSION = '1.51_2820';
13
14 =head1 NAME
15
16 Helios::Panoptes::JobInfo - Helios::Panoptes app providing Job Info view
17
18 =head1 DESCRIPTION
19
20 Helios::Panoptes::JobLog handles the display for the Panoptes Job Info.
21
22 =head1 CGI::APPLICATION METHODS
23
24 =head2 setup()
25
26 =cut
27
28 sub setup {
29 my $self = shift;
30 $self->start_mode('jobinfo');
31 $self->mode_param('rm');
32 $self->run_modes(
33 jobinfo => 'rm_jobinfo'
34 );
35
36 my $config = $self->parseConfig();
37
38 # connect to db
39 $self->dbh_config($config->{dsn},$config->{user},$config->{password}, {RaiseError => 1, AutoCommit => 1} );
40 }
41
42
43 =head2 teardown()
44
45 The only thing that currently happens in teardown() is the database is disconnected.
46
47 =cut
48
49 sub teardown {
50 $_[0]->dbh->disconnect();
51 }
52
53
54 =head1 RUN MODES
55
56 =head2 rm_jobinfo()
57
58 The rm_jobinfo() method handles the display of the Job Log page.
59
60 =cut
61
62 sub rm_jobinfo {
63 my $self = shift;
64 my $dbh = $self->dbh();
65 my $q = $self->query();
66 my %funcmap = $self->getFuncmapByFuncid();
67 my @loglevels = $self->getLogLevelList();
68 my %jobinfo;
69 my @errorinfo;
70 my @loginfo;
71 my @jobhistory;
72
73 my $jobid;
74 if ( defined($q->param('jobid')) ) { $jobid = $q->param('jobid'); }
75 unless ( defined($jobid) ) {
76 Helios::Error::InvalidArg->throw('The jobid parameter is required.');
77 }
78
79 # JOB
80 $jobinfo{jobid} = $jobid;
81 my $drvr = $self->initDriver();
82 my $sj = $drvr->lookup('TheSchwartz::Job' => $jobid);
83 if ( defined($sj) ) {
84 $jobinfo{service_name} = $funcmap{ $sj->funcid };
85 $jobinfo{insert_time} = defined($sj->insert_time) ? scalar localtime($sj->insert_time) : undef;
86 $jobinfo{run_after} = defined($sj->run_after) ? scalar localtime($sj->run_after) : undef;
87 $jobinfo{grabbed_until} = $sj->grabbed_until ? scalar localtime($sj->grabbed_until) : undef;
88 $jobinfo{arg} = $sj->arg()->[0];
89 $jobinfo{uniqkey} = $sj->uniqkey;
90 $jobinfo{priority} = $sj->priority;
91 $jobinfo{coalesce} = $sj->coalesce;
92 }
93
94 # ERROR
95 my $errtb_sql = qq{ SELECT funcid, error_time, message FROM error WHERE jobid = ? ORDER BY error_time DESC };
96 my $errtb_sth = $dbh->prepare_cached($errtb_sql);
97 $errtb_sth->execute($jobid);
98 my $errtb_rs = $errtb_sth->fetchall_arrayref();
99 $errtb_sth->finish();
100 foreach (@$errtb_rs) {
101 my %err;
102 $err{funcname} = $funcmap{ $_->[0] };
103 $err{error_time} = scalar localtime($_->[1]);
104 $err{message} = $_->[2];
105 push(@errorinfo, \%err);
106 }
107
108 # HELIOS_JOB_HISTORY_TB
109 my $jhtb_sql = qq{ SELECT funcid, insert_time, run_after, grabbed_until, complete_time, exitstatus, arg FROM helios_job_history_tb WHERE jobid = ? ORDER BY complete_time DESC };
110 my $jhtb_sth = $dbh->prepare_cached($jhtb_sql);
111 $jhtb_sth->execute($jobid);
112 my $jhtb_rs = $jhtb_sth->fetchall_arrayref();
113 $jhtb_sth->finish();
114 foreach (@$jhtb_rs) {
115 my %hist;
116 $hist{funcname} = $funcmap{ $_->[0] };
117 $hist{insert_time} = scalar localtime($_->[1]);
118 $hist{run_after} = scalar localtime($_->[2]);
119 $hist{grabbed_until} = scalar localtime($_->[3]);
120 $hist{complete_time} = scalar localtime($_->[4]);
121 $hist{exitstatus} = $_->[5];
122 $hist{arg} = $_->[6];
123 push(@jobhistory, \%hist);
124 }
125 # fill in info from job history if the job isn't in the queue
126 unless ($jobinfo{insert_time}) {
127 $jobinfo{service_name} = $jobhistory[0]->{funcname};
128 $jobinfo{insert_time} = $jobhistory[0]->{insert_time};
129 $jobinfo{run_after} = $jobhistory[0]->{run_after};
130 $jobinfo{grabbed_until} = $jobhistory[0]->{grabbed_until};
131 $jobinfo{arg} = $jobhistory[0]->{arg};
132 }
133
134
135 # HELIOS_LOG_TB
136 my $ltb_sql = qq{ SELECT log_time, host, process_id, funcid, job_class, priority, message FROM helios_log_tb WHERE jobid = ? ORDER BY log_time DESC };
137 my $ltb_sth = $dbh->prepare_cached($ltb_sql);
138 $ltb_sth->execute($jobid);
139 my $ltb_rs = $ltb_sth->fetchall_arrayref();
140 $ltb_sth->finish();
141 foreach(@$ltb_rs) {
142 my %log;
143 $log{log_time} = scalar localtime($_->[0]);
144 $log{host} = $_->[1];
145 $log{pid} = $_->[2];
146 $log{funcid} = $_->[3];
147 $log{job_class} = $_->[4];
148 $log{priority} = $loglevels[ $_->[5] ];
149 $log{message} = $_->[6];
150 push(@loginfo, \%log);
151 }
152
153 my $t = $self->load_tmpl('jobinfo.html', die_on_bad_params => 0, loop_context_vars => 1);
154 $t->param(TITLE => "Helios - Job Log " . $jobid);
155 $t->param(JOBID => $jobid);
156
157 $t->param(JOB_ARG => $jobinfo{arg});
158 $t->param(JOB_INSERT_TIME => $jobinfo{insert_time});
159 $t->param(JOB_RUN_AFTER => $jobinfo{run_after});
160 $t->param(JOB_SERVICE_NAME => $jobinfo{service_name});
161 $t->param(JOB_GRABBED_UNTIL => $jobinfo{grabbed_until});
162 # these are TheSchwartz::Job features that are technically supported,
163 # but Helios never actually uses itself. They're left out of the default
164 # template theme but could be added if a user needs to customize.
165 $t->param(JOB_UNIQUE_KEY => $jobinfo{uniqkey});
166 $t->param(JOB_PRIORITY => $jobinfo{priority});
167 $t->param(JOB_COALESCE => $jobinfo{coalesce});
168
169 $t->param(ERRORS => \@errorinfo);
170 $t->param(JOB_HISTORY => \@jobhistory);
171 $t->param(LOG_ENTRIES => \@loginfo);
172
173
174
175 return $t->output();
176 }
177
178
179 1;
180 __END__