From b8417cf19780c4c72ea62d539a11dda83cf0e907 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sat, 29 Sep 2018 06:06:09 +0000 Subject: [PATCH] Bug 15529 - Wrapping email sending up in the verbose flag Thus the cron email telling the administrator or support company that a second execution of the process_message_queue.pl cron whilst it is already running is only sent if it is wanted and verbose is set. Sponsored-By: New Zealand Parliamentary Library Signed-off-by: Mark Tompsett --- misc/cronjobs/process_message_queue.pl | 47 ++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl index 0a6d8c98f0..b15b595854 100755 --- a/misc/cronjobs/process_message_queue.pl +++ b/misc/cronjobs/process_message_queue.pl @@ -55,6 +55,12 @@ GetOptions( 'v|verbose' => \$verbose, 't|type' => \$type, ); + +sub usage { + pod2usage( -verbose => 2 ); + exit; +} + my $usage = << 'ENDUSAGE'; This script processes the message queue in the message_queue database @@ -70,7 +76,7 @@ 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 + -v --verbose: provides verbose output to STDOUT, if verbose is set then emails will be sent upon duplicate execution of this cronjob ENDUSAGE die $usage if $help; @@ -87,24 +93,27 @@ open(FOO, ">> $instancemessagequeuefile") or die "Cannot write to $instancemessa print "Getting the lock\n"; unless (flock ( FOO, LOCK_EX|LOCK_NB )) { -print "$0 is already running. Exiting.\n"; -#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 -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); + print "$0 is already running. Exiting.\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); + } } C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } ); -- 2.11.0