From a7903f0cc60222c26ea73968fff34eceae9c917b 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 Content-Type: text/plain; charset=utf-8 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 --- 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 85176e584d..94c458268c 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -73,6 +73,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, @@ -130,10 +133,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.30.2