From f28dfb24909222f89346b7438ec774e6cec96185 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 16 Jan 2024 14:46:20 -0300 Subject: [PATCH] Bug 35819: Notify NACK when Job ID not found --- misc/workers/background_jobs_worker.pl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl index fde3432143a..d7015d646f2 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -121,19 +121,22 @@ while (1) { } catch { Koha::Logger->get({ interface => 'worker' })->warn(sprintf "Frame not processed - %s", $_); return; - } finally { - $conn->ack( { frame => $frame } ); }; - next unless $args; - - # FIXME This means we need to have create the DB entry before - # It could work in a first step, but then we will want to handle job that will be created from the message received - my $job = Koha::BackgroundJobs->search( { id => $args->{job_id}, status => 'new' } )->next; + my $job; - unless( $job ) { - Koha::Logger->get( { interface => 'worker' } ) - ->warn( sprintf "Job %s not found, or has wrong status", $args->{job_id} ); + if ( $args ) { + $job = Koha::BackgroundJobs->search( { id => $args->{job_id}, status => 'new' } )->next; + unless( $job ) { + Koha::Logger->get( { interface => 'worker' } ) + ->warn( sprintf "Job %s not found, or has wrong status", $args->{job_id} ); + # nack to force requeue + $conn->nack( { frame => $frame } ); + next; + } + $conn->ack( { frame => $frame } ); + } + else { next; } -- 2.43.0