From 991338db3e4091bb6bfb044521e3ee775fe20340 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 25 Feb 2020 11:32:51 +0100 Subject: [PATCH] Bug 22417: [DO NOT PUSH] Adjust koha_worker.pl 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 | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/koha_worker.pl b/koha_worker.pl index 4ee28f3d46..f6efb07a54 100644 --- a/koha_worker.pl +++ b/koha_worker.pl @@ -3,34 +3,34 @@ use Modern::Perl; 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; +my @job_types = qw( batch_biblio_record_modification batch_authority_record_modification ); + +# FIXME cf note in Koha::BackgroundJob about $namespace +my $namespace = C4::Context->config('memcached_namespace'); +for my $job_type ( @job_types ) { + $conn->subscribe({ destination => sprintf("%s-%s", $namespace, $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; + say " [x] Received $body"; + my $args = decode_json($body); + + # FIXME This means we need to have create the DB entry before + # It could work in a first step, but then we will want to handle job that will be created from the message received + my $job = Koha::BackgroundJobs->find($args->{job_id}); + my $success = $job->process( $args ); + say " [x] Done"; + + $conn->ack( { frame => $frame } ); # FIXME depending on $success? +} +$conn->disconnect; -- 2.11.0