| 1 | # | ||||||||||
| 2 | # $Id: AutoSys.pm 68 2008-02-11 10:50:27Z 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; | ||||||||||
| 24 | |||||||||||
| 25 | 1 | require CA::AutoSys::Job; | |||||||||
| 26 | 1 | require CA::AutoSys::Status; | |||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 1 | ▶ | use DBI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 1 | $VERSION = '1.05'; | |||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 1 | ▶ | use vars qw(@ISA @EXPORT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 1 | @ISA = qw(Exporter); | |||||||||
| 39 | 1 | @EXPORT = qw(&new); | |||||||||
| 40 | |||||||||||
| 41 | 1 | our $errstr; | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 44 | 0 | my $self = {}; | |||||||||
| 45 | 0 | my $class = shift(); | |||||||||
| 46 | |||||||||||
| 47 | 0 | $errstr = ''; | |||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | my %args = @_; | |||||||||
| 51 | 0 | ▶ | $self->{dsn} = $args{dsn} ? $args{dsn} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | ▶ | $self->{server} = $args{server} ? $args{server} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | ▶ | $self->{user} = $args{user} ? $args{user} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | ▶ | $self->{password} = $args{password} ? $args{password} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | if (!defined($self->{dsn})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | ▶ | if (!defined($self->{server})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $errstr = "no dsn given in new()"; | |||||||||
| 60 | 0 | return undef; | |||||||||
| 61 | } | ||||||||||
| 62 | # Default to Sybase when no dsn was given... | ||||||||||
| 63 | 0 | $self->{dsn} = "dbi:Sybase:server=$self->{server}"; | |||||||||
| 64 | } | ||||||||||
| 65 | 0 | $self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{password}); | |||||||||
| 66 | 0 | ▶ | if (!$self->{dbh}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $errstr = "can't connect to dsn ".$self->{dsn}.": ".$DBI::errstr; | |||||||||
| 68 | 0 | return undef; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | bless($self); | |||||||||
| 72 | 0 | return $self; | |||||||||
| 73 | } # new() | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub find_jobs { | ||||||||
|
Subroutine
find_jobs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | 0 | my $self = shift(); | |||||||||
| 77 | 0 | my $job_name = shift(); | |||||||||
| 78 | 0 | my $job = CA::AutoSys::Job->new(parent => $self, database_handle => $self->{dbh}); | |||||||||
| 79 | 0 | return $job->find_jobs($job_name); | |||||||||
| 80 | } # find_jobs() | ||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | sub send_event { | ||||||||
|
Subroutine
send_event: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 83 | 0 | my $self = shift(); | |||||||||
| 84 | 0 | my ($job_name, $event, $status, $event_time); | |||||||||
| 85 | 0 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | my %args = @_; | |||||||||
| 87 | 0 | ▶ | $job_name = $args{job_name} ? $args{job_name} : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | ▶ | $event = $args{event} ? $args{event} : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | ▶ | $status = $args{status} ? $args{status} : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | ▶ | $event_time = $args{event_time} ? $args{event_time} : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 0 | my $sth = $self->{dbh}->prepare(qq{ | |||||||||
| 94 | exec sendevent '$event', '$job_name', '$status', '', '$event_time', '' | ||||||||||
| 95 | }); | ||||||||||
| 96 | |||||||||||
| 97 | 0 | $sth->execute(); | |||||||||
| 98 | |||||||||||
| 99 | 0 | my ($rc) = $sth->fetchrow_array(); | |||||||||
| 100 | 0 | return $rc; | |||||||||
| 101 | } # send_event() | ||||||||||
| 102 | |||||||||||
| 103 | 1 | 1; | |||||||||
| 104 | __END__ | ||||||||||