From b23df4c8c0b8239a507cc4ca1e2ba94af057d5f3 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 22 Dec 2022 22:17:04 +0000 Subject: [PATCH] Bug 32481: Limit prefetch size for background jobs worker This patch adds a prefetch size of 1 to the background jobs worker, so that it fetches 1 message at a time. Without this change, the RabbitMQ connection timeout when too many messages for slow tasks are fetched at the same time. To test: 0. Apply patch 1. Run background worker 2. Rapidly enqueue multiple jobs that in total will take longer than 30 minutes to process Bug 32481: Use correct prefetch syntax for RabbitMQ According to https://www.rabbitmq.com/stomp.html the header to use for managing the prefetch is "prefetch-count". You can verify the number of delivered and unacknowledged messages on a channel on a connection by running "rabbitmqctl list_channels" on the RabbitMQ host. This will tell you how many messages have been delivered and are awaiting acknowledgement Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi (cherry picked from commit cd89c383219eb9355b225b51219007a08b5e339e) Signed-off-by: Jacob O'Mara (cherry picked from commit 6238ce057e2b2784d6c4a178728cb92d515ac454) Signed-off-by: Lucas Gass (cherry picked from commit 0b206ff70962b02748e1456b3eec694f35c14451) Signed-off-by: Arthur Suzuki --- misc/background_jobs_worker.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl index 5a84d342ba..538cd93110 100755 --- a/misc/background_jobs_worker.pl +++ b/misc/background_jobs_worker.pl @@ -42,7 +42,11 @@ if ( $conn ) { # FIXME cf note in Koha::BackgroundJob about $namespace my $namespace = C4::Context->config('memcached_namespace'); for my $job_type ( @job_types ) { - $conn->subscribe({ destination => sprintf("/queue/%s-%s", $namespace, $job_type), ack => 'client' }); + $conn->subscribe({ + destination => sprintf("/queue/%s-%s", $namespace, $job_type), + ack => 'client', + 'prefetch-count' => 1, + }); } } while (1) { -- 2.20.1