From b683f776283b10657000d230a43394c2d6ff6d51 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. --- 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 3b90827c559..85176e584d2 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -124,23 +124,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.34.1