| 1 | # | ||||||||||||||||||||||||||||
| 2 | # $Id: Status.pm 57 2007-10-26 15:10:55Z sini $ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # CA::AutoSys - Perl Interface to CA's AutoSys job control. | ||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2007 Sinisa Susnjar <sini@cpan.org> | ||||||||||||||||||||||||||||
| 6 | # See LICENSE for terms of distribution. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # This library is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 9 | # modify it under the terms of the GNU Lesser General Public | ||||||||||||||||||||||||||||
| 10 | # License as published by the Free Software Foundation; either | ||||||||||||||||||||||||||||
| 11 | # version 2.1 of the License, or (at your option) any later version. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # This library is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||||||||||
| 16 | # Lesser General Public License for more details. | ||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||
| 18 | # You should have received a copy of the GNU Lesser General Public | ||||||||||||||||||||||||||||
| 19 | # License along with this library; if not, write to the Free Software | ||||||||||||||||||||||||||||
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | package CA::AutoSys::Status; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use vars qw(@ISA @EXPORT $VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 31 | 1 | @EXPORT = qw(&new &format_status &format_time); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | $VERSION = '1.03'; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | our %status_names = ( | |||||||||||||||||||||||||||
| 36 | 0 => ' ', # *empty* | ||||||||||||||||||||||||||||
| 37 | 1 => 'RU', # running | ||||||||||||||||||||||||||||
| 38 | 2 => ' 2', # *not defined* | ||||||||||||||||||||||||||||
| 39 | 3 => 'ST', # starting | ||||||||||||||||||||||||||||
| 40 | 4 => 'SU', # success | ||||||||||||||||||||||||||||
| 41 | 5 => 'FA', # failure | ||||||||||||||||||||||||||||
| 42 | 6 => 'TE', # terminated | ||||||||||||||||||||||||||||
| 43 | 7 => 'OI', # on ice | ||||||||||||||||||||||||||||
| 44 | 8 => 'IN', # inactive | ||||||||||||||||||||||||||||
| 45 | 9 => 'AC', # activated | ||||||||||||||||||||||||||||
| 46 | 10 => 'RE', # restart | ||||||||||||||||||||||||||||
| 47 | 11 => 'OH', # on hold | ||||||||||||||||||||||||||||
| 48 | 12 => 'QW', # queue wait | ||||||||||||||||||||||||||||
| 49 | 13 => '13', # *not defined* | ||||||||||||||||||||||||||||
| 50 | 14 => 'RD', # refresh dependencies | ||||||||||||||||||||||||||||
| 51 | 15 => 'RF', # refresh filewatcher | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 1 | NONE => 0, | |||||||||||||||||||||||||||
| 56 | RUNNING => 1, | ||||||||||||||||||||||||||||
| 57 | UNDEF_2 => 2, | ||||||||||||||||||||||||||||
| 58 | STARTING => 3, | ||||||||||||||||||||||||||||
| 59 | SUCCESS => 4, | ||||||||||||||||||||||||||||
| 60 | FAILURE => 5, | ||||||||||||||||||||||||||||
| 61 | TERMINATED => 6, | ||||||||||||||||||||||||||||
| 62 | ON_ICE => 7, | ||||||||||||||||||||||||||||
| 63 | INACTIVE => 8, | ||||||||||||||||||||||||||||
| 64 | ACTIVATED => 9, | ||||||||||||||||||||||||||||
| 65 | RESTART => 10, | ||||||||||||||||||||||||||||
| 66 | ON_HOLD => 11, | ||||||||||||||||||||||||||||
| 67 | QUEUE_WAIT => 12, | ||||||||||||||||||||||||||||
| 68 | UNDEF_13 => 13, | ||||||||||||||||||||||||||||
| 69 | REFRESH_DEP => 14, | ||||||||||||||||||||||||||||
| 70 | REFRESH_FW => 15 | ||||||||||||||||||||||||||||
| 71 | 1 | }; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | our %long_status = ( | |||||||||||||||||||||||||||
| 74 | 0 => "NONE", | ||||||||||||||||||||||||||||
| 75 | 1 => "RUNNING", | ||||||||||||||||||||||||||||
| 76 | 2 => "UNDEF_2", | ||||||||||||||||||||||||||||
| 77 | 3 => "STARTING", | ||||||||||||||||||||||||||||
| 78 | 4 => "SUCCESS", | ||||||||||||||||||||||||||||
| 79 | 5 => "FAILURE", | ||||||||||||||||||||||||||||
| 80 | 6 => "TERMINATED", | ||||||||||||||||||||||||||||
| 81 | 7 => "ON_ICE", | ||||||||||||||||||||||||||||
| 82 | 8 => "INACTIVE", | ||||||||||||||||||||||||||||
| 83 | 9 => "ACTIVATED", | ||||||||||||||||||||||||||||
| 84 | 10 => "RESTART", | ||||||||||||||||||||||||||||
| 85 | 11 => "ON_HOLD", | ||||||||||||||||||||||||||||
| 86 | 12 => "QUEUE_WAIT", | ||||||||||||||||||||||||||||
| 87 | 13 => "UNDEF_13", | ||||||||||||||||||||||||||||
| 88 | 14 => "REFRESH_DEP", | ||||||||||||||||||||||||||||
| 89 | 15 => "REFRESH_FW" | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 0 | my $self = {}; | |||||||||||||||||||||||||||
| 94 | 0 | my $class = shift(); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | $self->{last_start} = $args{last_start} ? $args{last_start} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $self->{last_end} = $args{last_end} ? $args{last_end} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $self->{status} = $args{status} ? $args{status} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $self->{status_time} = $args{status_time} ? $args{status_time} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $self->{name} = $long_status{$self->{status}}; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | $self->{run_num} = $args{run_num} ? $args{run_num} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $self->{ntry} = $args{ntry} ? $args{ntry} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $self->{exit_code} = $args{exit_code} ? $args{exit_code} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | bless($self); | |||||||||||||||||||||||||||
| 109 | 0 | return $self; | |||||||||||||||||||||||||||
| 110 | } # new() | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub format_status { | ||||||||||||||||||||||||||
|
Subroutine
format_status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 0 | my $status = shift(); | |||||||||||||||||||||||||||
| 114 | 0 | return $status_names{$status}; | |||||||||||||||||||||||||||
| 115 | } # format_status() | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub format_time { | ||||||||||||||||||||||||||
|
Subroutine
format_time: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 0 | my $time = shift(); | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | if (!defined($time) || $time == 999999999) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $time or $time == 999999999
MC/DC0%0/2
not defined $time or $time == 999999999
not defined $time
$time == 999999999
Truth table0%0/3
not(A) or B
A= not defined $timeB= $time == 999999999
| |||||||||||||||||||||||||||||
| 120 | 0 | return "-----"; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 0 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = localtime($time); | |||||||||||||||||||||||||||
| 123 | 0 | $mon++; | |||||||||||||||||||||||||||
| 124 | 0 | $year += 1900; | |||||||||||||||||||||||||||
| 125 | 0 | return sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec); | |||||||||||||||||||||||||||
| 126 | # return sprintf("%02d/%02d/%04d %02d:%02d:%02d (%d)", $mon, $mday, $year, $hour, $min, $sec, $time); | ||||||||||||||||||||||||||||
| 127 | } # format_time() | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||