~ubuntu-branches/ubuntu/natty/otrs2/natty-updates

« back to all changes in this revision

Viewing changes to bin/GenericAgent.pl

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2009-01-11 00:16:27 UTC
  • mto: (20.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20090111001627-u70e4vlj5sfw5kzk
Tags: upstream-2.3.3
ImportĀ upstreamĀ versionĀ 2.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# bin/GenericAgent.pl - a generic agent -=> e. g. close ale emails in a specific queue
4
4
# Copyright (C) 2001-2008 OTRS AG, http://otrs.org/
5
5
# --
6
 
# $Id: GenericAgent.pl,v 1.49 2008/05/08 09:36:57 mh Exp $
 
6
# $Id: GenericAgent.pl,v 1.50 2008/09/08 06:48:58 martin Exp $
7
7
# --
8
8
# This program is free software; you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
30
30
use lib dirname($RealBin) . "/Kernel/cpan-lib";
31
31
 
32
32
use vars qw($VERSION %Jobs @ISA);
33
 
$VERSION = qw($Revision: 1.49 $) [1];
 
33
$VERSION = qw($Revision: 1.50 $) [1];
34
34
 
35
35
use Getopt::Std;
36
36
use Kernel::Config;
123
123
    # process all jobs
124
124
    my %DBJobs = $CommonObject{GenericAgentObject}->JobList();
125
125
    for my $DBJob ( sort keys %DBJobs ) {
 
126
        # get job
126
127
        my %DBJobRaw = $CommonObject{GenericAgentObject}->JobGet( Name => $DBJob );
127
 
        my $Run      = 0;
128
 
        my $False    = 0;
129
 
 
130
 
        # check last run
 
128
 
 
129
        # check requred params (need min. one param)
 
130
        my $Schedule;
 
131
        for my $Key (qw( ScheduleDays ScheduleMinutes ScheduleHours ) ) {
 
132
            if ( $DBJobRaw{$Key} ) {
 
133
                $Schedule = 1;
 
134
            }
 
135
        }
 
136
        next if !$Schedule;
 
137
 
 
138
        # next if jobs is invalid
 
139
        next if !$DBJobRaw{Valid};
 
140
 
 
141
        # get time params to check last and current run
131
142
        my ( $Sec, $Min, $Hour, $Day, $Month, $Year, $WDay )
132
143
            = $CommonObject{TimeObject}->SystemTime2Date(
133
144
            SystemTime => $CommonObject{TimeObject}->SystemTime(),
134
145
            );
135
 
 
136
146
        if ( $Min =~ /(.)./ ) {
137
 
            $Min = ($1) . "0";
 
147
            $Min = ($1) . '0';
138
148
        }
 
149
 
 
150
        # check ScheduleDays
139
151
        if ( $DBJobRaw{ScheduleDays} ) {
140
152
            my $Match = 0;
141
153
            for ( @{ $DBJobRaw{ScheduleDays} } ) {
142
154
                if ( $_ eq $WDay ) {
143
155
                    $Match = 1;
144
 
                    $Run   = 1;
145
 
                }
146
 
            }
147
 
            if ( !$Match ) {
148
 
                $False = 1;
149
 
            }
150
 
        }
151
 
        if ( !defined $DBJobRaw{ScheduleMinutes} ) {
152
 
            @{ $DBJobRaw{ScheduleMinutes} } = qw(00 10 20 30 40 50);
153
 
        }
154
 
        my $Match = 0;
155
 
        for ( @{ $DBJobRaw{ScheduleMinutes} } ) {
156
 
            if ( $_ == $Min ) {
157
 
                $Match = 1;
158
 
                $Run   = 1;
159
 
            }
160
 
        }
161
 
        if ( !$Match ) {
162
 
            $False = 1;
163
 
        }
164
 
        if ( !defined $DBJobRaw{ScheduleHours} ) {
165
 
            @{ $DBJobRaw{ScheduleHours} }
166
 
                = qw(00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23);
167
 
        }
168
 
        $Match = 0;
169
 
        for ( @{ $DBJobRaw{ScheduleHours} } ) {
170
 
            if ( $_ == $Hour ) {
171
 
                $Match = 1;
172
 
                $Run   = 1;
173
 
            }
174
 
        }
175
 
        if ( !$Match ) {
176
 
            $False = 1;
177
 
        }
178
 
 
179
 
        # check if job is invalid
180
 
        if ( !$DBJobRaw{Valid} ) {
181
 
            $False = 1;
 
156
                }
 
157
            }
 
158
            next if !$Match;
 
159
        }
 
160
 
 
161
        # check ScheduleMinutes
 
162
        if ( $DBJobRaw{ScheduleMinutes} ) {
 
163
            my $Match = 0;
 
164
            for ( @{ $DBJobRaw{ScheduleMinutes} } ) {
 
165
                if ( $_ == $Min ) {
 
166
                    $Match = 1;
 
167
                }
 
168
            }
 
169
            next if !$Match;
 
170
        }
 
171
 
 
172
        # check ScheduleHours
 
173
        if ( $DBJobRaw{ScheduleHours} ) {
 
174
            my $Match = 0;
 
175
            for ( @{ $DBJobRaw{ScheduleHours} } ) {
 
176
                if ( $_ == $Hour ) {
 
177
                    $Match = 1;
 
178
                }
 
179
            }
 
180
            next if !$Match;
182
181
        }
183
182
 
184
183
        # check if job already was running
189
188
            )
190
189
        {
191
190
            print "Job '$DBJob' already finished!\n";
192
 
            $False = 1;
 
191
            next;
193
192
        }
194
 
        if ( !$False ) {
195
193
 
196
 
            # log event
197
 
            $CommonObject{GenericAgentObject}->JobRun(
198
 
                Job    => $DBJob,
199
 
                Limit  => $Opts{l},
200
 
                UserID => $UserIDOfGenericAgent,
201
 
            );
202
 
        }
 
194
        # log event
 
195
        $CommonObject{GenericAgentObject}->JobRun(
 
196
            Job    => $DBJob,
 
197
            Limit  => $Opts{l},
 
198
            UserID => $UserIDOfGenericAgent,
 
199
        );
203
200
    }
204
201
 
205
202
    # delete pid lock