Lines 38-48
my $help = 0;
Link Here
|
38 |
my $verbose = 0; |
38 |
my $verbose = 0; |
39 |
my $type = q{}; |
39 |
my $type = q{}; |
40 |
|
40 |
|
41 |
use MIME::Lite; |
|
|
42 |
use Mail::Sendmail; |
43 |
use Encode; |
44 |
use Net::SMTP; |
45 |
|
46 |
use Fcntl ':flock'; |
41 |
use Fcntl ':flock'; |
47 |
|
42 |
|
48 |
|
43 |
|
Lines 76-121
This script has the following parameters :
Link Here
|
76 |
-l --limit: The maximum number of messages to process for this run |
71 |
-l --limit: The maximum number of messages to process for this run |
77 |
-m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.) |
72 |
-m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.) |
78 |
-h --help: this message |
73 |
-h --help: this message |
79 |
-v --verbose: provides verbose output to STDOUT, if verbose is set then emails will be sent upon duplicate execution of this cronjob |
74 |
-v --verbose: provides verbose output to STDOUT. |
|
|
75 |
Also useful for testing duplicate runs. Make sure the KohaAdminEmail preference is set. |
80 |
ENDUSAGE |
76 |
ENDUSAGE |
81 |
|
77 |
|
82 |
die $usage if $help; |
78 |
die $usage if $help; |
83 |
|
79 |
|
84 |
cronlogaction(); |
80 |
cronlogaction(); |
85 |
|
81 |
|
86 |
print "start of program\n"; |
82 |
if ($verbose) { print "start of program\n"; } |
87 |
my $logdir = C4::Context->config('logdir'); |
83 |
my $logdir = C4::Context->config('logdir'); |
88 |
|
84 |
|
89 |
chomp $logdir; |
85 |
chomp $logdir; |
90 |
my $instancemessagequeuefile = $logdir . "/messagequeue.lock"; |
86 |
my $instancemessagequeuefile = $logdir . "/messagequeue.lock"; |
91 |
open(FOO, ">> $instancemessagequeuefile") or die "Cannot write to $instancemessagequeuefile: $!"; |
87 |
open(FOO, ">> $instancemessagequeuefile") or die "Cannot write to $instancemessagequeuefile: $!"; |
92 |
|
88 |
|
93 |
print "Getting the lock\n"; |
89 |
my $letter_code = ''; |
|
|
90 |
if ($verbose) { print "Getting the lock\n"; } |
94 |
unless (flock ( FOO, LOCK_EX|LOCK_NB )) { |
91 |
unless (flock ( FOO, LOCK_EX|LOCK_NB )) { |
95 |
|
92 |
|
96 |
print "$0 is already running. Exiting.\n"; |
93 |
print STDERR "$0 is already running!\n"; |
97 |
#If verbose is set send email to inform administrator another process_message_queue.pl cron was attempted to run whilst previous execution of the file is taking place. |
94 |
#If verbose is set send email to inform administrator another process_message_queue.pl cron was attempted to run whilst previous execution of the file is taking place. |
98 |
# Configure accordingly |
95 |
# Configure accordingly |
99 |
|
96 |
|
100 |
if ($verbose) { |
97 |
C4::Letters::EnqueueLetter( |
101 |
MIME::Lite->send( 'smtp', ''); |
98 |
0, #borrowernumber |
102 |
my $email = MIME::Lite->new( |
99 |
'process_message_queue.pl cron is already running', #subject |
103 |
To => ' ', |
100 |
'process_message_queue.pl cron is already running', #content |
104 |
From => ' ', |
101 |
'', #metadata |
105 |
Type => 'TEXT', |
102 |
'DUPLICATE_PROCESS_MESSAGE_QUEUE', #letter_code |
106 |
Subject => 'process_message_queue.pl cron is already running', |
103 |
'email', #message_transport_type |
107 |
Data => 'process_message_queue.pl cron is already running', |
104 |
'pending', #status |
108 |
); |
105 |
C4::Context->preference('KohaAdminEmail'), #to_address |
109 |
|
106 |
C4::Context->preference('KohaAdminEmail'), #from_address |
110 |
$email->attach( |
107 |
'text' #content_type |
111 |
Type => 'Text', |
108 |
); |
112 |
Data => 'process_message_queue.pl cron is already running', |
109 |
$letter_code = 'DUPLICATE_PROCESS_MESSAGE_QUEUE'; |
113 |
); |
|
|
114 |
$email->send(); |
115 |
exit(1); |
116 |
} |
117 |
} |
110 |
} |
118 |
|
111 |
|
119 |
C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } ); |
112 |
C4::Letters::SendQueuedMessages( |
120 |
sleep(15); |
113 |
{ |
121 |
print "End of process_message_queue.pl cron process"; |
114 |
verbose => $verbose, |
|
|
115 |
username => $username, |
116 |
password => $password, |
117 |
method => $method, |
118 |
limit => $limit, |
119 |
type => $type, |
120 |
letter_code => $letter_code, |
121 |
} |
122 |
); |
123 |
if ($verbose) { |
124 |
sleep(15); |
125 |
print "End of process_message_queue.pl cron process"; |
126 |
} |
122 |
- |
|
|