From 7ab53318e0a75ed24f685ec5dc275c2a26801610 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 19 Feb 2020 14:00:03 +0100 Subject: [PATCH] Bug 22417: Switch to STOMP apt install rabbitmq-server service rabbitmq-server start rabbitmq-plugins enable rabbitmq_stomp apt install libnet-stomp-perl cp debian/scripts/koha-functions.sh /usr/share/koha/bin/koha-functions.sh cp debian/scripts/koha-worker /usr/bin/ koha-worker --start kohadev tail -f /var/log/rabbitmq/* Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Cook Signed-off-by: Marcel de Rooy Bug 22417: Remove useless use statement Signed-off-by: Marcel de Rooy --- Koha/BackgroundJob.pm | 29 +++---------- Koha/BackgroundJob/BatchUpdateAuthority.pm | 1 - Koha/BackgroundJob/BatchUpdateBiblio.pm | 6 +-- .../prog/en/modules/admin/background_jobs.tt | 8 ++-- misc/background_jobs_worker.pl | 43 ++++++++----------- tools/batch_record_modification.pl | 1 - 6 files changed, 28 insertions(+), 60 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 3224b5d486..252091489e 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -3,7 +3,7 @@ package Koha::BackgroundJob; use Modern::Perl; use JSON qw( encode_json decode_json ); use Carp qw( croak ); -use Net::RabbitFoot; +use Net::Stomp; use C4::Context; use Koha::DateUtils qw( dt_from_string ); @@ -13,15 +13,9 @@ use base qw( Koha::Object ); sub connect { my ( $self ); - my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( - host => 'localhost', # TODO Move this to KOHA_CONF - port => 5672, - user => 'guest', - pass => 'guest', - vhost => '/', - ); - - return $conn; + my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } ); + $stomp->connect( { login => 'guest', passcode => 'guest' } ); + return $stomp; } sub enqueue { @@ -47,19 +41,8 @@ sub enqueue { $json_args = encode_json $job_args, my $conn = $self->connect; - my $channel = $conn->open_channel(); - - $channel->declare_queue( - queue => $job_type, - durable => 1, - ); - - $channel->publish( - exchange => '', - routing_key => $job_type, # TODO Must be different? - body => $json_args, - ); - $conn->close; + $conn->send({destination => $job_type, body => $json_args}); + return $job_id; } diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm index 4d43606f2c..682501a261 100644 --- a/Koha/BackgroundJob/BatchUpdateAuthority.pm +++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm @@ -4,7 +4,6 @@ use Modern::Perl; use Koha::BackgroundJobs; use Koha::DateUtils qw( dt_from_string ); use JSON qw( encode_json decode_json ); -use Net::RabbitFoot; use base 'Koha::BackgroundJob'; diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm index 990b34902a..09c53fa185 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -4,20 +4,17 @@ use Modern::Perl; use Koha::BackgroundJobs; use Koha::DateUtils qw( dt_from_string ); use JSON qw( encode_json decode_json ); -use Net::RabbitFoot; use base 'Koha::BackgroundJob'; -our $channel; sub process { - my ( $self, $args, $channel ) = @_; + my ( $self, $args ) = @_; my $job_type = $args->{job_type}; my $job = Koha::BackgroundJobs->find( $args->{job_id} ); if ( !exists $args->{job_id} || !$job || $job->status eq 'cancelled' ) { - $channel->ack; return; } @@ -77,7 +74,6 @@ sub process { ->data(encode_json $job_data); $job->status('finished') if $job->status ne 'cancelled'; $job->store; - $channel->ack(); # FIXME Is that ok even on failure? } sub enqueue { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt index 8009711e92..d1cc6cec7d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt @@ -141,9 +141,9 @@ View [% IF job.status == 'new' || job.status == 'started' %] - Cancel + Cancel [% END %] - Replay + Replay [% END %] @@ -171,11 +171,11 @@ [% INCLUDE 'datatables.inc' %]