Bugzilla – Attachment 108034 Details for
Bug 22417
Add a task queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22417: Switch to STOMP
Bug-22417-Switch-to-STOMP.patch (text/plain), 8.08 KB, created by
David Cook
on 2020-08-11 08:18:06 UTC
(
hide
)
Description:
Bug 22417: Switch to STOMP
Filename:
MIME Type:
Creator:
David Cook
Created:
2020-08-11 08:18:06 UTC
Size:
8.08 KB
patch
obsolete
>From 57fc61c0d88284d5543d758db4ef933ecafeda48 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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 <tomascohen@theke.io> > >Signed-off-by: David Cook <dcook@prosentient.com.au> >--- > Koha/BackgroundJob.pm | 31 ++++------------ > Koha/BackgroundJob/BatchUpdateAuthority.pm | 1 - > Koha/BackgroundJob/BatchUpdateBiblio.pm | 6 +-- > .../prog/en/modules/admin/background_jobs.tt | 8 ++-- > koha_worker.pl | 1 - > misc/background_jobs_worker.pl | 43 +++++++++------------- > tools/batch_record_modification.pl | 1 - > 7 files changed, 30 insertions(+), 61 deletions(-) > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 3224b5d486..5aa2cd67a8 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -3,25 +3,21 @@ 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 ); > use Koha::BackgroundJobs; > >+use Scalar::Util qw( weaken ); >+ > 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 +43,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 @@ > <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" > })); >diff --git a/koha_worker.pl b/koha_worker.pl >index 13af3dfd70..4ee28f3d46 100644 >--- a/koha_worker.pl >+++ b/koha_worker.pl >@@ -1,7 +1,6 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use Net::RabbitFoot; > use JSON qw( encode_json decode_json ); > > use Koha::BackgroundJob::BatchUpdateBiblio; >diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl >index 2d7264b139..6bc7335453 100755 >--- a/misc/background_jobs_worker.pl >+++ b/misc/background_jobs_worker.pl >@@ -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,); >- >-$channel->consume( >- on_consume => sub { >- my $var = shift; >- my $body = $var->{body}->{payload}; >- say " [x] Received $body"; >- >- my $args = decode_json( $body ); >- >- Koha::BackgroundJob::BatchUpdateBiblio->process($args, $channel); >- say " [x] Done"; >- }, >- no_ack => 0, >-); >- >-warn "waiting forever"; >-# Wait forever >-AnyEvent->condvar->recv; >+ >+$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 >+ } >+ >+ my $body = $frame->body; >+ my $args = decode_json($body); >+ >+ my $success = Koha::BackgroundJob::BatchUpdateBiblio->process( $args ); >+ >+ $conn->ack( { frame => $frame } ); # FIXME depending on $success? >+} >+$conn->disconnect; >diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl >index d0f017674b..23d54de053 100755 >--- a/tools/batch_record_modification.pl >+++ b/tools/batch_record_modification.pl >@@ -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 ); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22417
:
105542
|
105543
|
107385
|
107386
|
107387
|
107388
|
107389
|
107390
|
107391
|
107392
|
107393
|
107394
|
107395
|
107396
|
107397
|
107398
|
107399
|
107400
|
107401
|
107402
|
107403
|
107404
|
107405
|
107406
|
107481
|
107482
|
107682
|
108023
|
108024
|
108025
|
108026
|
108027
|
108028
|
108029
|
108030
|
108031
|
108032
|
108033
|
108034
|
108035
|
108036
|
108037
|
108038
|
108039
|
108040
|
108041
|
108042
|
108043
|
108044
|
108045
|
108046
|
108047
|
109270
|
109271
|
109319
|
109320
|
109321
|
109322
|
109323
|
109324
|
109325
|
109326
|
109327
|
109328
|
109329
|
109330
|
109331
|
109332
|
109333
|
109334
|
109335
|
109336
|
109337
|
109338
|
109339
|
109340
|
109341
|
109342
|
109343
|
109344
|
109345
|
109350
|
109351
|
109355
|
109390
|
109391
|
109392
|
109393
|
109394
|
109395
|
109396
|
109397
|
109398
|
109399
|
109400
|
109401
|
109402
|
109403
|
109404
|
109405
|
109406
|
109407
|
109408
|
109409
|
109410
|
109411
|
109412
|
109413
|
109414
|
109415
|
109416
|
109417
|
109418
|
109474
|
109475
|
109476
|
109477
|
110150
|
111091
|
111092
|
111093
|
111094
|
111095
|
111096
|
111097
|
111098
|
111099
|
111100
|
111101
|
111102
|
111103
|
111104
|
111105
|
111106
|
111107
|
111108
|
111109
|
111110
|
111111
|
111112
|
111113
|
111114
|
111115
|
111116
|
111117
|
111118
|
111119
|
111120
|
111121
|
111238
|
111239
|
111245