From d8ef5d25fb8f238a94be52f52b8841ea7a34db58 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Feb 2019 21:44:51 -0300 Subject: [PATCH] Bug 22417: [DO NOT PUSH] Add simple worker and add_job scripts Content-Type: text/plain; charset=utf-8 Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Cook Signed-off-by: Marcel de Rooy --- koha_worker.pl | 37 +++++++++++++++++++++++++++++++++++++ new_koha_job.pl | 26 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 koha_worker.pl create mode 100644 new_koha_job.pl diff --git a/koha_worker.pl b/koha_worker.pl new file mode 100644 index 0000000000..13af3dfd70 --- /dev/null +++ b/koha_worker.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Net::RabbitFoot; +use JSON qw( encode_json decode_json ); + +use Koha::BackgroundJob::BatchUpdateBiblio; +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, +); + +# Wait forever +AnyEvent->condvar->recv; diff --git a/new_koha_job.pl b/new_koha_job.pl new file mode 100644 index 0000000000..b29aa82d94 --- /dev/null +++ b/new_koha_job.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use Modern::Perl; +use C4::Context; +use Koha::BackgroundJob::BatchUpdateBiblio; +use Koha::BackgroundJob; + +use Net::RabbitFoot; + +my $mmtid = 1; +my $record_type = 'biblio'; +my @record_ids = ( 1, 2, 3 ); + +C4::Context->_new_userenv(42); +C4::Context->set_userenv( 51, 51, 42, 'koha', 'koha', 'CPL', 'CPL', 1 ); + +say " [x] Enqueuing BatchUpdateBiblio mmtid=$mmtid with biblionumber=" + . join( ',', @record_ids ); +Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue( + { + job_type => 'batch_record_modification', + mmtid => $mmtid, + record_type => $record_type, + record_ids => \@record_ids, + } +); -- 2.11.0