From c22f483213f004ed95884a9da03ac4a7f2e9364c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Tue, 16 Sep 2025 15:07:20 -0300 Subject: [PATCH] Bug 40820: Fix STOMP connection warnings when JobsNotificationMethod is 'polling' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The background job workers are showing STOMP/RabbitMQ connection error warnings even when the JobsNotificationMethod system preference was set to 'polling', which doesn't require a message broker connection. This patch adds checks for the JobsNotificationMethod preference before displaying connection warnings, so warnings only appear when STOMP is actually expected to be available. Changes: - misc/workers/background_jobs_worker.pl: Check syspref before warning - misc/workers/es_indexer_daemon.pl: Check syspref before warning Test plan: 1. Set JobsNotificationMethod to 'polling' 2. Run background_jobs_worker.pl - should not show STOMP warnings 3. Run es_indexer_daemon.pl - should not show STOMP warnings 4. Set JobsNotificationMethod to 'STOMP' without RabbitMQ running 5. Run workers - should show appropriate STOMP connection warnings 6. Sign off :-D Signed-off-by: Tomás Cohen Arazi --- misc/workers/background_jobs_worker.pl | 18 +++++++++++------- misc/workers/es_indexer_daemon.pl | 14 +++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/misc/workers/background_jobs_worker.pl b/misc/workers/background_jobs_worker.pl index 81e980998d..afb5f603e5 100755 --- a/misc/workers/background_jobs_worker.pl +++ b/misc/workers/background_jobs_worker.pl @@ -90,14 +90,18 @@ unless (@queues) { push @queues, 'default'; } +my $notification_method = C4::Context->preference('JobsNotificationMethod') // 'STOMP'; + my ( $conn, $error ); -try { - $conn = Koha::BackgroundJob->connect; -} catch { - $error = sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; -}; -$error ||= "Cannot connect to the message broker, the jobs will be processed anyway" unless $conn; -warn $error if $error; +if ( $notification_method eq 'STOMP' ) { + try { + $conn = Koha::BackgroundJob->connect; + } catch { + $error = sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; + }; + $error ||= "Cannot connect to the message broker, the jobs will be processed anyway" unless $conn; + warn $error if $error; +} my $pm = Parallel::ForkManager->new($max_processes); diff --git a/misc/workers/es_indexer_daemon.pl b/misc/workers/es_indexer_daemon.pl index 42fb24d6a8..9b69fb59f7 100755 --- a/misc/workers/es_indexer_daemon.pl +++ b/misc/workers/es_indexer_daemon.pl @@ -81,12 +81,16 @@ warn "Not using Elasticsearch" unless C4::Context->preference('SearchEngine') eq my $logger = Koha::Logger->get( { interface => 'worker' } ); +my $notification_method = C4::Context->preference('JobsNotificationMethod') // 'STOMP'; + my $conn; -try { - $conn = Koha::BackgroundJob->connect; -} catch { - warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; -}; +if ( $notification_method eq 'STOMP' ) { + try { + $conn = Koha::BackgroundJob->connect; + } catch { + warn sprintf "Cannot connect to the message broker, the jobs will be processed anyway (%s)", $_; + }; +} if ($conn) { -- 2.51.0