1 | # |
---|
2 | # Copyright (c) 2004-2007 - Consultas, PKG.fr |
---|
3 | # |
---|
4 | # This file is part of A2P. |
---|
5 | # |
---|
6 | # A2P is free software; you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation; either version 2 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # A2P is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with A2P; if not, write to the Free Software |
---|
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | # |
---|
20 | # $Id: Archiver.pm 3 2007-10-18 16:20:19Z guillaume $ |
---|
21 | # |
---|
22 | |
---|
23 | package A2P::Archiver ; |
---|
24 | |
---|
25 | # Derived class from Thread.pm |
---|
26 | use base qw(A2P::Thread); |
---|
27 | |
---|
28 | use strict ; |
---|
29 | use integer ; |
---|
30 | use Socket ':crlf' ; |
---|
31 | use A2P::Globals ; |
---|
32 | use A2P::Syslog ; |
---|
33 | use A2P::archivage ; |
---|
34 | use A2P::Com qw( IsCom comJOB ); |
---|
35 | use A2P::JobStatus 'a2pjobstate' ; |
---|
36 | |
---|
37 | BEGIN { |
---|
38 | our $VERSION = sprintf "%s", q$Rev: 397 $ =~ /(\d[0-9.]+)\s+/ ; |
---|
39 | } |
---|
40 | our $VERSION ; |
---|
41 | |
---|
42 | ################################################################################ |
---|
43 | ## Archivage thread object ## |
---|
44 | ################################################################################ |
---|
45 | sub Do { |
---|
46 | my $self = shift ; |
---|
47 | my $ref = shift ; |
---|
48 | |
---|
49 | my $Ret = 0 ; |
---|
50 | |
---|
51 | my @Job = &IsCom( comJOB , $$ref ); |
---|
52 | |
---|
53 | if ( @Job == 2 ) { |
---|
54 | my ( $Job , $archreq ) = @Job ; |
---|
55 | |
---|
56 | &Debug("Received Arch request for $Job"); |
---|
57 | |
---|
58 | $archreq =~ s/\.arch$// ; # Squeezes arch extension |
---|
59 | |
---|
60 | # Keep internal stats |
---|
61 | &UPSTAT('ARCH_REQ'); |
---|
62 | |
---|
63 | # Archivage main sub-routine connector |
---|
64 | if ( $ARCH_ENABLED < 100 ) { |
---|
65 | $Ret = &ArchivageMain( $archreq ); |
---|
66 | |
---|
67 | } else { |
---|
68 | # Archivage must be simulated |
---|
69 | $Ret = $ARCH_ENABLED == 100 ? 0 : |
---|
70 | ( rand($ARCH_ENABLED) > 99 ? 1 : 0 ) ; |
---|
71 | } |
---|
72 | |
---|
73 | # Keep status and log error |
---|
74 | my $status_step = 'o' ; |
---|
75 | my $status = { JID => $Job , STATUS => 'ARCHIVED' } ; |
---|
76 | |
---|
77 | if ($Ret) { |
---|
78 | $self->ThisError("Archivage of '$archreq.pdf' returned with $Ret" . |
---|
79 | ( ($!) ? ": $! $? $@" : "" )); |
---|
80 | $status->{ABTERM} = 'Not archived'; |
---|
81 | $status->{STATUS} = 'KO' ; |
---|
82 | $status_step = 'A' ; |
---|
83 | } |
---|
84 | |
---|
85 | my ( $JobId ) = $Job =~ /^(.*)-\d+$/ ; |
---|
86 | &a2pjobstate( $JobId || $Job , 10, $status_step, $status ) |
---|
87 | or &Info("Can't set job status '$status_step'"); |
---|
88 | |
---|
89 | # Keep internal stats |
---|
90 | $Ret ? &UPSTAT('BAD_ARCH_REQ') : &UPSTAT('GOOD_ARCH_REQ'); |
---|
91 | |
---|
92 | $self->Return( $Job , $Ret ? $Ret : DONE ); |
---|
93 | $self->AnswerDone( $Job ); |
---|
94 | |
---|
95 | } else { |
---|
96 | # Keep internal stats |
---|
97 | &UPSTAT('BAD_ARCH_FORMAT'); |
---|
98 | |
---|
99 | $self->ThisError("Can't understand request '$$ref'"); |
---|
100 | |
---|
101 | $Ret = 9 ; |
---|
102 | |
---|
103 | if (@Job) { |
---|
104 | # Return exec status even for bad format to not break job processing |
---|
105 | $self->Return( $Job[0] , $Ret ); |
---|
106 | $self->AnswerDone( $Job[0] ); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | return $Ret ? 0 : 1 ; |
---|
111 | } |
---|
112 | |
---|
113 | sub ThreadInit { |
---|
114 | undef $SOCK ; |
---|
115 | } |
---|
116 | |
---|
117 | &Debug("Module " . __PACKAGE__ . " v$VERSION loaded"); |
---|
118 | |
---|
119 | 1; |
---|