line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: Job.pm 67 2008-02-11 10:49:36Z sini $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# CA::AutoSys - Perl Interface to CA's AutoSys job control. |
5
|
|
|
|
|
|
|
# Copyright (c) 2007 Sinisa Susnjar |
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::Job; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
require CA::AutoSys::Status; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
28
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
31
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA @EXPORT $VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
815
|
|
32
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
33
|
|
|
|
|
|
|
@EXPORT = qw(&new); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$VERSION = '1.03'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $debug = 0; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
40
|
0
|
|
|
0
|
0
|
|
my $self = {}; |
41
|
0
|
|
|
|
|
|
my $class = shift(); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if (@_) { |
44
|
0
|
|
|
|
|
|
my %args = @_; |
45
|
0
|
0
|
|
|
|
|
$self->{parent} = $args{parent} ? $args{parent} : undef; |
46
|
0
|
0
|
|
|
|
|
$self->{dbh} = $args{database_handle} ? $args{database_handle} : undef; |
47
|
0
|
0
|
|
|
|
|
$self->{sth} = $args{statement_handle} ? $args{statement_handle} : undef; |
48
|
0
|
0
|
|
|
|
|
$self->{parent_job} = $args{parent_job} ? $args{parent_job} : undef; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s) created.\n", $self); } |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
bless($self); |
54
|
0
|
|
|
|
|
|
return $self; |
55
|
|
|
|
|
|
|
} # new() |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _fetch_next { |
58
|
0
|
|
|
0
|
|
|
my $self = shift(); |
59
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): _fetch_next()\n", $self); } |
|
0
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if (my $h = $self->{sth}->fetchrow_hashref()) { |
61
|
0
|
0
|
|
|
|
|
if (defined($self->{parent_job})) { |
62
|
0
|
|
|
|
|
|
$self->{parent_job}->{child_cnt}++; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
foreach (keys %{ $h }) { |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->{$_} = $h->{$_}; |
66
|
0
|
0
|
|
|
|
|
$self->{$_} =~ s/^[ ]*$//g if ($self->{$_}); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$self->{status} = CA::AutoSys::Status->new(parent => $self->{parent}, last_start => $self->{last_start}, |
69
|
|
|
|
|
|
|
last_end => $self->{last_end}, status => $self->{status}, |
70
|
|
|
|
|
|
|
run_num => $self->{run_num}, ntry => $self->{ntry}, |
71
|
|
|
|
|
|
|
exit_code => $self->{exit_code}, |
72
|
|
|
|
|
|
|
status_time => $self->{status_time}); |
73
|
0
|
|
|
|
|
|
return $self; |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
|
$self->{sth}->finish(); |
76
|
0
|
|
|
|
|
|
return undef; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} # _fetch_next() |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _query { |
81
|
0
|
|
|
0
|
|
|
my $query = qq{ |
82
|
|
|
|
|
|
|
select j.*, s.*, j2.job_name as box_name |
83
|
|
|
|
|
|
|
from job j join job_status s |
84
|
|
|
|
|
|
|
on j.joid = s.joid |
85
|
|
|
|
|
|
|
left outer join job j2 |
86
|
|
|
|
|
|
|
on j.box_joid = j2.joid |
87
|
|
|
|
|
|
|
}; |
88
|
0
|
|
|
|
|
|
return $query; |
89
|
|
|
|
|
|
|
} # _query() |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub find_jobs { |
92
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
93
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): find_jobs()\n", $self); } |
|
0
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $job_name = shift(); |
95
|
0
|
|
|
|
|
|
my $query = _query() . qq{ |
96
|
|
|
|
|
|
|
where j.job_name like '$job_name' |
97
|
|
|
|
|
|
|
order by j.joid |
98
|
|
|
|
|
|
|
}; |
99
|
0
|
|
|
|
|
|
my $sth = $self->{dbh}->prepare($query); |
100
|
0
|
0
|
|
|
|
|
if (!$sth->execute()) { |
101
|
0
|
|
|
|
|
|
$self->{parent}->{errstr} = "can't select info for job ".$job_name.": ".$sth->errstr(); |
102
|
0
|
|
|
|
|
|
return undef; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
return CA::AutoSys::Job->new(parent => $self->{parent}, database_handle => $self->{dbh}, |
105
|
|
|
|
|
|
|
statement_handle => $sth); |
106
|
|
|
|
|
|
|
} # find_jobs() |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub find_children { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
110
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): find_children()\n", $self); } |
|
0
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $query = _query() . qq{ |
112
|
|
|
|
|
|
|
where j.box_joid = $self->{joid} |
113
|
|
|
|
|
|
|
order by j.joid |
114
|
|
|
|
|
|
|
}; |
115
|
0
|
|
|
|
|
|
my $sth = $self->{dbh}->prepare($query); |
116
|
0
|
0
|
|
|
|
|
if ($debug) { |
117
|
0
|
|
|
|
|
|
printf("DEBUG: Job(%s): selecting children for joid %d\n", $self, $self->{joid}); |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
|
$self->{child_cnt} = 0; |
120
|
0
|
0
|
|
|
|
|
if (!$sth->execute()) { |
121
|
0
|
|
|
|
|
|
$self->{parent}->{errstr} = "can't select children for job ".$self->{job_name}.": ".$sth->errstr(); |
122
|
0
|
|
|
|
|
|
return undef; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
return CA::AutoSys::Job->new(parent => $self->{parent}, database_handle => $self->{dbh}, |
125
|
|
|
|
|
|
|
statement_handle => $sth, parent_job => $self); |
126
|
|
|
|
|
|
|
} # find_children() |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub next_job { |
129
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
130
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): next_job()\n", $self); } |
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $self->_fetch_next(); |
132
|
|
|
|
|
|
|
} # next_job() |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub next_child { |
135
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
136
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): next_child()\n", $self); } |
|
0
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $self->_fetch_next(); |
138
|
|
|
|
|
|
|
} # next_child() |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub get_status { |
141
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
142
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): get_status()\n", $self); } |
|
0
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return $self->{status}; |
144
|
|
|
|
|
|
|
} # get_status() |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub has_children { |
147
|
0
|
|
|
0
|
1
|
|
my $self = shift(); |
148
|
0
|
0
|
|
|
|
|
if ($debug) { printf("DEBUG: Job(%s): has_children()\n", $self); } |
|
0
|
|
|
|
|
|
|
149
|
0
|
0
|
0
|
|
|
|
if (!defined($self->{child_cnt}) || $self->{child_cnt} == 0) { |
150
|
0
|
|
|
|
|
|
return 0; |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
return 1; |
153
|
|
|
|
|
|
|
} # has_children() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |