Bug 40820: Fix STOMP connection warnings when JobsNotificationMethod is 'polling'

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 <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 4ff1f4ca9c)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Tomás Cohen Arazi 2025-09-16 15:07:20 -03:00 committed by Paul Derscheid
parent 4cd910b176
commit c9f4566aa6
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 20 additions and 12 deletions

View File

@ -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);

View File

@ -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) {