@@ -, +, @@ while running process_message_queue.pl --- misc/cronjobs/process_message_queue.pl | 60 +++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) --- a/misc/cronjobs/process_message_queue.pl +++ a/misc/cronjobs/process_message_queue.pl @@ -28,6 +28,12 @@ BEGIN { use C4::Letters; use C4::Log; use Getopt::Long; +use MIME::Lite; +use Mail::Sendmail; +use Encode; +use Net::SMTP; + +use Fcntl ':flock'; my $username = undef; my $password = undef; @@ -68,14 +74,50 @@ die $usage if $help; cronlogaction(); -C4::Letters::SendQueuedMessages( - { - verbose => $verbose, - username => $username, - password => $password, - method => $method, - limit => $limit, - type => $type, +print "start of program\n"; + +foreach my $instance (`koha-list --enabled`) { + chomp $instance; + my $instancemessagequeuefile = "/var/lock/koha/" . $instance . "/messagequeue.lock"; + + + open(FOO, ">> $instancemessagequeuefile") or die "Cannot write to $instancemessagequeuefile: $!"; + 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', 'mail.catalyst.net.nz'); + + + 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, + limit => $limit, + type => $type, + } + ); + print "End of process_message_queue.pl cron process"; +} --