From 7dc49e26e2da0e7423258ddc50d6c534339c655a Mon Sep 17 00:00:00 2001 From: Mark Hofstetter Date: Sat, 14 Sep 2024 13:39:43 +0200 Subject: [PATCH] Bug 35655: Only use STOMP if JobsNotificationMethod set to do so This patch makes the background jobs (jobs from now on) connect step not try to connect to the STOMP broker, unless explicitly told to do so. This is achieved by using a newly introduced system preference `JobsNotificationMethod` which falls back to STOMP if undefined. The "about" page now has 3 states for + Message broker: Using SQL polling + Message broker: Using SQL polling (Fallback, Error connecting to RabbitMQ) + Message broker: Using RabbitMQ The goal for this patch is to stop flooding the logs on very busy sites when Rabbit is not being used. This shouldn't predate any efforts on making the STOMP based jobs brokering mechanism solid and usable. To test: 1. On clean `main`, run: $ ktd --shell 2. Open the logs on a separate terminal: $ ktd --shell k$ tail -f /var/log/koha/kohadev/*.log 3. Stage some MARC for import => SUCCESS: No warnings about STOMP 4. Import the staged records => SUCCESS: No warnings about STOMP 5. Stop rabbitmq: k$ sudo service rabbitmq-server stop 6. Repeat 2-4 => FAIL: The logs say it couldn't connect to STOMP 7. Apply this patches and run: k$ restart_all 8a. See the "about" page, should read: Message broker: Using SQL polling (Fallback, Error connecting to RabbitMQ) 8b. Repeat 2-4 should work with one warning in the 9. Start rabbit: k$ sudo service rabbitmq-server start k$ restart_all (not really necessary) 10a. See the "about" page, should read: Message broker: Using RabbitMQ 10b. Repeat 2-4 => SUCCESS: No warnings about STOMP 11. Change the `JobsNotificationMethod` system preference to *polling* and stop rabbit: k$ sudo service rabbitmq-server stop k$ restart_all 12a. See the "about" page, should read: Message broker: Using SQL polling 12b. Repeat 2-4 => SUCCESS: No warnings about STOMP, not even on startup 13. Sign off :-D Signed-off-by: Mark Hofstetter --- Koha/BackgroundJob.pm | 8 +++++--- about.pl | 10 ++++++++-- koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index c1e305e59f..6e066e51c7 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -81,9 +81,12 @@ sub connect { $credentials->{passcode} = $config->{password} if $config->{password}; $credentials->{host} = $config->{vhost} if $config->{vhost}; } - my $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); + + my $stomp; + try { - $stomp = $self->connect; + $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); + $stomp->connect( $credentials ); } catch { warn "Cannot connect to broker " . $_; $stomp = undef; @@ -134,7 +137,6 @@ sub enqueue { $job_args->{job_id} = $self->id; my $conn = $self->connect; - return $self->id unless $conn; $json_args = $json->encode($job_args); diff --git a/about.pl b/about.pl index 751ad0d395..c8ff0658b2 100755 --- a/about.pl +++ b/about.pl @@ -907,8 +907,14 @@ sub message_broker_check { { # BackgroundJob - test connection to message broker my $conn = Koha::BackgroundJob->connect; - if (!$conn) { - $template->param( warnConnectBroker => C4::Context->preference('JobsNotificationMethod') ); + if (! $conn) { + if (C4::Context->preference('JobsNotificationMethod') eq 'STOMP' ) { + $template->param( warnConnectBroker => 'Error connecting' ); + } else { + $template->param( + warnConnectBroker => C4::Context->preference('JobsNotificationMethod') + ); + } } } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index 0713215662..13e7c652c3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -202,7 +202,9 @@ Message broker: - [% IF warnConnectBroker %] + [% IF warnConnectBroker == 'Error connecting' %] + Using SQL polling (Fallback, Error connecting to RabbitMQ) + [% ELSIF warnConnectBroker %] Using SQL polling [% ELSE %] Using RabbitMQ -- 2.39.2