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 <tomascohen@theke.io> Signed-off-by: David Cook <dcook@prosentient.com.au> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 22417: Remove useless use statement Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
1a6c56f949
commit
9251623b8d
|
|
@ -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();
|
||||
$conn->send({destination => $job_type, body => $json_args});
|
||||
|
||||
$channel->declare_queue(
|
||||
queue => $job_type,
|
||||
durable => 1,
|
||||
);
|
||||
|
||||
$channel->publish(
|
||||
exchange => '',
|
||||
routing_key => $job_type, # TODO Must be different?
|
||||
body => $json_args,
|
||||
);
|
||||
$conn->close;
|
||||
return $job_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -141,9 +141,9 @@
|
|||
<td class="actions">
|
||||
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job.id | html %]"><i class="fa fa-eye"></i> View</a>
|
||||
[% IF job.status == 'new' || job.status == 'started' %]
|
||||
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&id=[% job.id | html %]"><i class="fa fa-pencil"></i> Cancel</a>
|
||||
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/background_jobs.pl?op=cancel&id=[% job.id | html %]"><i class="fa fa-trash"></i> Cancel</a>
|
||||
[% END %]
|
||||
<a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&id=[% job.id | html %]"><i class="fa fa-trash"></i> Replay</a>
|
||||
<a class="btn btn-default btn-xs disabled" href="/cgi-bin/koha/admin/background_jobs.pl?op=replay&id=[% job.id | html %]"><i class="fa fa-refresh"></i> Replay</a>
|
||||
</td>
|
||||
</tr>
|
||||
[% END %]
|
||||
|
|
@ -171,11 +171,11 @@
|
|||
[% INCLUDE 'datatables.inc' %]
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#table_cities").dataTable($.extend(true, {}, dataTablesDefaults, {
|
||||
$("#table_background_jobs").dataTable($.extend(true, {}, dataTablesDefaults, {
|
||||
"aoColumnDefs": [
|
||||
{ "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
|
||||
],
|
||||
"aaSorting": [[ 1, "asc" ]],
|
||||
"aaSorting": [[ 0, "desc" ]],
|
||||
"iDisplayLength": 10,
|
||||
"sPaginationType": "full_numbers"
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -23,30 +23,21 @@ use Koha::BackgroundJob;
|
|||
|
||||
my $conn = Koha::BackgroundJob->connect;
|
||||
|
||||
my $channel = $conn->open_channel();
|
||||
|
||||
my $job_type = 'batch_biblio_record_modification';
|
||||
$channel->declare_queue(
|
||||
queue => $job_type,
|
||||
durable => 1,
|
||||
);
|
||||
|
||||
$channel->qos(prefetch_count => 1,);
|
||||
$conn->subscribe({ destination => $job_type, ack => 'client' });
|
||||
while (1) {
|
||||
my $frame = $conn->receive_frame;
|
||||
if ( !defined $frame ) {
|
||||
# maybe log connection problems
|
||||
next; # will reconnect automatically
|
||||
}
|
||||
|
||||
$channel->consume(
|
||||
on_consume => sub {
|
||||
my $var = shift;
|
||||
my $body = $var->{body}->{payload};
|
||||
say " [x] Received $body";
|
||||
my $body = $frame->body;
|
||||
my $args = decode_json($body);
|
||||
|
||||
my $args = decode_json( $body );
|
||||
my $success = Koha::BackgroundJob::BatchUpdateBiblio->process( $args );
|
||||
|
||||
Koha::BackgroundJob::BatchUpdateBiblio->process($args, $channel);
|
||||
say " [x] Done";
|
||||
},
|
||||
no_ack => 0,
|
||||
);
|
||||
|
||||
warn "waiting forever";
|
||||
# Wait forever
|
||||
AnyEvent->condvar->recv;
|
||||
$conn->ack( { frame => $frame } ); # FIXME depending on $success?
|
||||
}
|
||||
$conn->disconnect;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ use Modern::Perl;
|
|||
use CGI;
|
||||
use List::MoreUtils qw( uniq );
|
||||
use JSON qw( encode_json );
|
||||
use Net::RabbitFoot;
|
||||
|
||||
use C4::Auth qw( get_template_and_user );
|
||||
use C4::Output qw( output_html_with_http_headers );
|
||||
|
|
|
|||
Loading…
Reference in New Issue