From 5fa868614ecb884773c7b1c5828ec7f956819208 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Jan 2024 10:14:21 +0100 Subject: [PATCH] Bug 35819: nack and not requeue if frame is invalid If a frame cannot be correctly processed (most probably because the body is not valid JSON) then we are not acking or nacking the frame and the worker is stuck. In this specific case we should nack without requeuing the frame. NOTE that requeue must be 'true' or 'false', not 1 or 0, or the default 'true' will be used. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit 83940925685af338be659ef7baa04a40bed9d97d) Signed-off-by: Fridolin Somers (cherry picked from commit 87e3d35e84dbfe4f2bc3b7b8d67bd54e38cdc64b) Signed-off-by: Lucas Gass --- misc/workers/background_jobs_worker.pl | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl index c77c37473e..61c21e77bf 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -125,23 +125,23 @@ while (1) { return; }; - my $job; - - 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, requeue => 1 } ); - Time::HiRes::sleep(0.5); - next; - } - $conn->ack( { frame => $frame } ); - } else { + unless ( $args ) { + Koha::Logger->get({ interface => 'worker' })->warn(sprintf "Frame does not have correct args, ignoring it"); + $conn->nack( { frame => $frame, requeue => 'false' } ); + next; + } + + my $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, requeue => 'true' } ); + Time::HiRes::sleep(0.5); next; } + $conn->ack( { frame => $frame } ); $pm->start and next; srand(); # ensure each child process begins with a new seed -- 2.39.5