From 0f7d1aae4fad2392323ec4aa5169376b87628544 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 1 Aug 2024 21:48:10 +0000 Subject: [PATCH] Bug 37552: Wrap auto renewal attempt in eval to ensure script does not die When libraries have a lot of checkouts, or an AMH, checkins can happen while the cron is running. This patch simply adds an eval around the auto renewal attempt in case of early check in or other errors. You can verify cron completed by enabling cronjob log in system preferences and checking the action logs To test: 1 - Add 'sleep(10);' to automatic_renewals.pl 2 - Set circulation rules to enable automatic renewals 3 - Issue an item to a patron 4 - perl misc/cronjobs/automatic_renewals.pl -v 5 - Confirm item would not be renewed 6 - perl misc/cronjobs/automatic_renewals.pl -v -c 7 - Quickly check in the item 8 - The cronjob dies DBIx::Class::Row::update(): Can't update Koha::Schema::Result::Issue=HASH(0x586e1a674fb0): row not found at /kohadevbox/koha/Koha/Object.pm line 172 9 - Apply patch 10 - Checkout the item again 11 - perl misc/cronjobs/automatic_renewals.pl -v -c 12 - Quickly checkin the item 13 - You get a warning, but the cron completes Signed-off-by: CJ Lynce --- misc/cronjobs/automatic_renewals.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 013fc12b60..fd1370d676 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -213,7 +213,15 @@ sub _ProcessRenewals { $wants_digest = 0; } - my ( $success, $error, $updated ) = $auto_renew->attempt_auto_renew( { confirm => $confirm } ); + my ( $success, $error, $updated ); + eval { + ( $success, $error, $updated ) = $auto_renew->attempt_auto_renew( { confirm => $confirm } ); + }; + if( $@ ){ + print "An error was encounter in processing auto renewal for issue id: " . $auto_renew->issue_id ."\n"; + print "$@ \n"; + next; + } if ($success) { if ($verbose) { say sprintf "Issue id: %s for borrower: %s and item: %s %s be renewed.", -- 2.39.2