From 1cc35cdbf6fbfe161f75f84861576279e4378b25 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 8 Oct 2024 02:20:12 +0000 Subject: [PATCH] Bug 34027: (follow-up) Make sleep seconds a command-line param Use --logs-sleep SECONDS to specify how many seconds Koha should wait between batches when deleting action logs. Defaults to 3 Sponsored-by: Auckland University of Technology Sponsored-by: Catalyst IT Signed-off-by: Kyle M Hall --- misc/cronjobs/cleanup_database.pl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 3bf4a3bb0be..456f73a74e7 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -31,6 +31,7 @@ use constant DEFAULT_JOBS_PURGEDAYS => 1; use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; use constant DEFAULT_EDIFACT_MSG_PURGEDAYS => 365; use constant DEFAULT_LOGS_BATCHSIZE => 1000; +use constant DEFAULT_LOGS_BATCHSLEEP => 3; use Getopt::Long qw( GetOptions ); use Try::Tiny; @@ -60,7 +61,7 @@ use Koha::UploadedFiles; sub usage { print STDERR < $command_line_options } ); @@ -233,6 +236,7 @@ GetOptions( 'reports:i' => \$reports, 'edifact-messages:i' => \$edifact_msg_days, 'logs-batch:i' => \$logs_batch, + 'logs-sleep:i' => \$logs_sleep, ) || usage(1); # Use default values @@ -248,6 +252,7 @@ $jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) @jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; $edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; $logs_batch = DEFAULT_LOGS_BATCHSIZE if defined($logs_batch) && $logs_batch == 0; +$logs_sleep = DEFAULT_LOGS_BATCHSLEEP if defined($logs_sleep) && $logs_sleep == 0; @statistics_types = ( @statistics_types, @Koha::Statistic::pseudonymization_types ) if defined($statistics_type_pseudo); @statistics_types = keys %{ { map { $_, 1 } @statistics_types } }; # remove duplicate types @@ -408,7 +413,7 @@ if ($pZ3950) { if ($pLogs) { print "Purging records from action_logs.\n" if $verbose; - for (0..10000){ + for ( 0 .. 10000 ) { $dbh->do(q{ INSERT INTO action_logs (user,timestamp) VALUES (52,"2022-01-01 09:00:00") }); $dbh->do(q{ UPDATE action_logs SET timestamp = "2020-01-01 10:00:00" ORDER BY action_id DESC LIMIT 1 }); } @@ -440,7 +445,7 @@ if ($pLogs) { do { $sth->execute(@query_params) or die $dbh->errstr; $rows_deleted = $sth->rows; - sleep 3; # Adjust sleep time as needed + sleep $logs_sleep; } while ( $rows_deleted == $logs_batch ); } else { $sth->execute(@query_params) or die $dbh->errstr; -- 2.39.5