Bugzilla – Attachment 78211 Details for
Bug 15529
Process Message Queue may send duplicate emails if process is launched twice
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15529 - Lock /var/lock/koha/<instance>/messagequeue.lock while running process_message_queue.pl
Bug-15529---Lock-varlockkohainstancemessagequeuelo.patch (text/plain), 3.20 KB, created by
Alex Buckley
on 2018-08-28 02:08:25 UTC
(
hide
)
Description:
Bug 15529 - Lock /var/lock/koha/<instance>/messagequeue.lock while running process_message_queue.pl
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2018-08-28 02:08:25 UTC
Size:
3.20 KB
patch
obsolete
>From 3cad7aa113b7d817dd96937a53853c94bb9580f8 Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Sat, 25 Aug 2018 23:53:21 +1200 >Subject: [PATCH] Bug 15529 - Lock /var/lock/koha/<instance>/messagequeue.lock > while running process_message_queue.pl > >The script loops through every enabled instance. It checks if the messagequeue.lock file is locked in the instance directory. > >If not then the cronjob runs. > >If the lock file is locked then this is logged and a email is sent out. > >Test plan: >1. In two terminals open koha-shell and try to run >./process_message_queue.pl and notice you can run the script multiple >times simulataneously without a warning/error being displayed > >2. Apply patch > >3. Repeast step 1 and notice that the second of the two scripts to be >run will output text saying './process_message_queue.pl is already >running. Exiting' > >In this case the aforementioned text is displayed and the body of the >cronjob is not run. > >4. The first cronjob script to run, runs without issues > >Sponsored-By: Parliament Library >--- > misc/cronjobs/process_message_queue.pl | 49 +++++++++++++++++++++++++++------- > 1 file changed, 40 insertions(+), 9 deletions(-) > >diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl >index 93f5c35..11ed6aa 100755 >--- a/misc/cronjobs/process_message_queue.pl >+++ b/misc/cronjobs/process_message_queue.pl >@@ -28,6 +28,11 @@ BEGIN { > use C4::Letters; > use C4::Log; > use Getopt::Long; >+use MIME::Lite; >+use Mail::Sendmail; >+use Encode; >+ >+use Fcntl ':flock'; > > my $username = undef; > my $password = undef; >@@ -68,14 +73,40 @@ 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"; >+ >+my $instancedirectory; >+foreach my $instance (`koha-list --enabled`) { >+ 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 >+ my $email = MIME::Lite->build( >+ To => ' ', >+ From => ' ', >+ Type => 'TEXT', >+ Subject => 'process_message_queue.pl cron is already running', >+ Data => 'process_message_queue.pl cron is already running', >+ contenttype => 'charset="UTF-8"', >+ ); >+ $email->send('smpt', ' '); >+ 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"; >+} >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15529
:
78205
|
78210
|
78211
|
78212
|
78582
|
78918
|
79649
|
79719
|
79726
|
79910
|
79911
|
79912
|
79913
|
80256