From dbc93f2de91b943b10ae8bfdbce83f791c580e96 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Mon, 1 Oct 2018 13:51:30 +0000 Subject: [PATCH] Bug 15529: Followup to send without more libraries This uses the letter_code parameter to limit the current duplicate run of the process_message_queue.pl script to just this one message. We don't care about receiving duplicate warning messages as much as we care about sending patrons duplicate messages. Works as described, passes QA test tool. Signed-off-by: Alex Buckley --- misc/cronjobs/process_message_queue.pl | 70 +++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl index b15b595854..43e18f2f6f 100755 --- a/misc/cronjobs/process_message_queue.pl +++ b/misc/cronjobs/process_message_queue.pl @@ -38,11 +38,6 @@ my $help = 0; my $verbose = 0; my $type = q{}; -use MIME::Lite; -use Mail::Sendmail; -use Encode; -use Net::SMTP; - use Fcntl ':flock'; @@ -76,46 +71,59 @@ This script has the following parameters : -l --limit: The maximum number of messages to process for this run -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.) -h --help: this message - -v --verbose: provides verbose output to STDOUT, if verbose is set then emails will be sent upon duplicate execution of this cronjob + -v --verbose: provides verbose output to STDOUT. + Also useful for testing duplicate runs. Make sure the KohaAdminEmailAddress preference is set. ENDUSAGE die $usage if $help; cronlogaction(); -print "start of program\n"; +if ($verbose) { print "start of program\n"; } my $logdir = C4::Context->config('logdir'); chomp $logdir; my $instancemessagequeuefile = $logdir . "/messagequeue.lock"; -open(FOO, ">> $instancemessagequeuefile") or die "Cannot write to $instancemessagequeuefile: $!"; +my $fh; +open $fh, '>>', $instancemessagequeuefile or die "Cannot write to $instancemessagequeuefile: $!"; -print "Getting the lock\n"; -unless (flock ( FOO, LOCK_EX|LOCK_NB )) { +my $letter_code = ''; +if ($verbose) { print "Getting the lock\n"; } +unless (flock ( $fh, LOCK_EX|LOCK_NB )) { - print "$0 is already running. Exiting.\n"; + print STDERR "$0 is already running!\n"; #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. # Configure accordingly - if ($verbose) { - MIME::Lite->send( 'smtp', ''); - my $email = MIME::Lite->new( - To => ' ', - From => ' ', - Type => 'TEXT', - Subject => 'process_message_queue.pl cron is already running', - Data => 'process_message_queue.pl cron is already running', - ); - - $email->attach( - Type => 'Text', - Data => 'process_message_queue.pl cron is already running', - ); - $email->send(); - exit(1); - } + my $null_borrower = undef; + my $is_queued = C4::Letters::EnqueueLetter( { + borrowernumber => $null_borrower, #borrowernumber + letter => { + title => 'process_message_queue.pl cron is already running', #subject + content => 'process_message_queue.pl cron is already running', #content + metadata => '', #metadata + code => 'DUPLICATE_PROCESS_MESSAGE_QUEUE', #letter_code + 'content-type' => 'text/plain; charset="UTF-8"', #content_type + }, + message_transport_type => 'email', #message_transport_type + to_address => C4::Context->preference('KohaAdminEmailAddress'), #to_address + from_address => C4::Context->preference('KohaAdminEmailAddress'), #from_address + } ); + $letter_code = 'DUPLICATE_PROCESS_MESSAGE_QUEUE'; } -C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } ); -sleep(15); -print "End of process_message_queue.pl cron process"; +C4::Letters::SendQueuedMessages( + { + verbose => $verbose, + username => $username, + password => $password, + method => $method, + limit => $limit, + type => $type, + letter_code => $letter_code, + } +); +if ($verbose) { + sleep(15); + print "End of process_message_queue.pl cron process"; +} -- 2.11.0