Bug 23571: Prevent concurrent execution of fines.pl
authorTomas Cohen Arazi <tomascohen@theke.io>
Sun, 12 Apr 2020 13:27:57 +0000 (10:27 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 14 Apr 2020 15:59:01 +0000 (16:59 +0100)
commit0d4fed889904c5eeba05f12bdbf8d14f0e3ae0a8
treed329d1475461926cb671abd520473ac77d0f0a17
parent83cde3858e5bfaf0619ecd4e9075d47e7063f199
Bug 23571: Prevent concurrent execution of fines.pl

This patch introduces locking in fines.pl. It does so by leveraging on
bug 25109, which introduces a generic locking implementation on
Koha::Script.

The introduced changes:
1. Try to get the lock
2.a. If success, normal execution happens
2.b. If rejected, cronlogaction is called with a meaningful message and
  a normal exit happens, so we don't flood the logs in vain. --verbose
  will make the script print the same message on STDERR, as already is
  the case with this script

To test:
1. Apply this patch
2. In two separate consoles run:
   $ kshell
  k$ perl misc/cronjobs/fines.pl --verbose
SUCCESS => The first one runs normally, the second one exists really fast
  and prints a message about the lock.
3. Sign off :-D

Sponsored-by: Orex Digital
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
misc/cronjobs/fines.pl