From d8dc98f7c519f706eb994f2a0898f5de99ddfe1a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 26 Jan 2024 14:25:56 +0100 Subject: [PATCH] Bug 35819: Improve logging Log (warn) if the job will be processed later, but add a debug however. Have a specific log for bad status Signed-off-by: Tomas Cohen Arazi Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit 30e69ebc5644f8b3d0a79c5c36aeb5038b632a30) Signed-off-by: Fridolin Somers (cherry picked from commit f8af6d50280137dfa94a1a04bccaf3139fb3a519) Signed-off-by: Lucas Gass --- misc/workers/background_jobs_worker.pl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl index 61c21e77bf..d319c12a94 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -74,6 +74,9 @@ my $max_processes = $ENV{MAX_PROCESSES}; $max_processes ||= C4::Context->config('background_jobs_worker')->{max_processes} if C4::Context->config('background_jobs_worker'); $max_processes ||= 1; +my $not_found_retries = {}; +my $max_retries = $ENV{MAX_RETRIES} || 10; + GetOptions( 'm|max-processes=i' => \$max_processes, 'h|help' => \$help, @@ -131,10 +134,29 @@ while (1) { next; } - my $job = Koha::BackgroundJobs->search( { id => $args->{job_id}, status => 'new' } )->next; + my $job = Koha::BackgroundJobs->find( $args->{job_id} ); + + if ( $job && $job->status ne 'new' ) { + Koha::Logger->get( { interface => 'worker' } ) + ->warn( sprintf "Job %s has wrong status %s", $args->{job_id}, $job->status ); + + # nack without requeue, we do not want to process this frame again + $conn->nack( { frame => $frame, requeue => 'false' } ); + next; + } + unless ($job) { + if ( ++$not_found_retries->{$args->{job_id}} >= $max_retries ) { + Koha::Logger->get( { interface => 'worker' } ) + ->warn( sprintf "Job %s not found, no more retry", $args->{job_id} ); + + # nack without requeue, we do not want to process this frame again + $conn->nack( { frame => $frame, requeue => 'false' } ); + next; + } + Koha::Logger->get( { interface => 'worker' } ) - ->warn( sprintf "Job %s not found, or has wrong status", $args->{job_id} ); + ->debug( sprintf "Job %s not found, will retry later", $args->{job_id} ); # nack to force requeue $conn->nack( { frame => $frame, requeue => 'true' } ); -- 2.39.5