From 8ef9ac5445bd102501dadc02bdda2aee73ae4293 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 Signed-off-by: Emily Lamancusa Signed-off-by: Katrin Fischer --- misc/cronjobs/automatic_renewals.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 013fc12b60..d5018a46e1 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -213,7 +213,13 @@ 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 encountered 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.5