@@ -, +, @@ scripts --- 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 --- a/koha_worker.pl +++ a/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; --- a/new_koha_job.pl +++ a/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, + } +); --